auto Questions
1
Solved
I'm looking for a simple example when C++ 23 auto(x) could be useful.
This is what I have so far:
struct A {
A() = default;
explicit A(const A&) {} // copy constructor
};
struct B {
A child;...
1
Solved
Consider the following code (godbolt link):
#include <cstdio>
int main() {
auto foo = operator new;
void* mem = foo(1);
printf("%p", mem);
}
This code compiles on GCC, Clang, a...
Runaway asked 28/7, 2023 at 12:44
5
Solved
I'm currently reading "Expert C Programming - Deep C Secrets", and just came across this:
The storage class specifier auto is never needed. It is mostly meaningful to a compiler-writer
m...
Eudora asked 21/6, 2023 at 21:12
11
Solved
How can I find out what type the compiler deduced when using the auto keyword?
Example 1: Simpler
auto tickTime = 0.001;
Was this deduced as a float or a double?
Example 2: More complex (and m...
Godbeare asked 8/8, 2016 at 2:39
3
The C23 standard apparently has introduced using "auto" keyword for auto type deduction, see here, just like in C++11. However, there seems to be some differences.
According to here, http...
Fyrd asked 14/5, 2023 at 17:33
4
(This is a follow-up from "Are there any realistic use cases for `decltype(auto)` variables?")
Consider the following scenario - I want to pass a function f to another function invoke_log_return w...
Sphacelus asked 10/8, 2019 at 18:59
9
Solved
I get warning signed/unsigned mismatch for the following code:
auto n = a.size();
for (auto i = 0; i < n; i++) {
}
The problem is that by assigning 0 to i it becomes int rather than size_t.
S...
9
Solved
I had a perception that, type of a lambda is a function pointer. When I performed following test, I found it to be wrong (demo).
#define LAMBDA [] (int i) -> long { return 0; }
int main ()
{
lo...
4
I was wondering if there's an elegant solution for the following issue:
Let's say I'd like to have a variable holding a value with a pretty complex type and would the compiler to automatically infe...
2
Solved
Please take a look at the following simple code:
class Foo
{
public:
Foo(){}
~Foo(){}
Foo(const Foo&){}
Foo& operator=(const Foo&) { return *this; }
};
static Foo g_temp;
const F...
0
How to automatically increment the assembly version number in C# .
NET6 no longer has AssemblyInfo.cs, as we all know
And i try the answer at
How to auto increment the version (eg. “1.0.*”) of a .N...
1
template<template<auto> class> struct A {};
template<int&> struct B {};
A<B> a;
int main() {}
All three compilers MSVC, GCC and Clang in their latest versions accept ...
Speiss asked 23/12, 2022 at 0:17
2
How can I disable, that after typing a dot (.) Visual Studio will automatically print FileStyleUriParser?
Don't get me wrong, I want the suggestions, but I don't want Visual Studio to automaticall...
Taxis asked 27/1, 2022 at 12:38
3
So, when I use auto keyword in VS2015 with something simple, like this:
As you can see, it shows the variable's type, but, when I try something a bit more complex (or defined in another file?), i...
Readymix asked 29/11, 2016 at 16:28
5
Solved
I recently came across the std::any class, introduced in C++17, based on boost::any. This class can "hold an instance of any type" and auto automatically deduces the data type of a variab...
9
Solved
In this response:
https://mcmap.net/q/151800/-sequence-zip-function-for-c-11
this program is given:
std::vector<int> vi{ 0, 2, 4 };
std::vector<std::string> vs{ "1", "3", "5", "7" };...
3
Solved
Does C++11 allow declaring non-static data members as 'auto' if they are initialized in the declaration? For example:
struct S
{
auto x = 5; // in place of 'int x = 5;', which is definitely allow...
Ralphralston asked 3/7, 2012 at 0:28
6
Solved
As I understand it, both decltype and auto will attempt to figure out what the type of something is.
If we define:
int foo () {
return 34;
}
Then both declarations are legal:
auto x = foo();
cout...
Encephalitis asked 23/8, 2012 at 2:41
4
Solved
How does generic lambda work (auto keyword as an argument type) in C++14 standard?
Is it based on C++ templates where for each different argument type compiler generates a new function with the s...
6
Solved
For example I wanted to have a variable of type auto because I'm not sure what type it will be.
When I try to declare it in class/struct declaration it's giving me this error:
Cannot deduce au...
2
Solved
I have a struct with a method called call which has a const overload. The one and only argument is a std::function which either takes a int reference or a const int reference, depending on the over...
Vociferant asked 8/4, 2022 at 12:29
3
Solved
I came across the following code:
template <typename T, typename T1> auto compose(T a, T1 b) -> decltype(a + b) {
return a+b;
}
There is one thing I cannot understand:
Where could I find...
5
Solved
I was somehow surprised that the following code compiles and runs (vc2012 & gcc4.7.2)
class Foo {
struct Bar { int i; };
public:
Bar Baz() { return Bar(); }
};
int main() {
Foo f;
// Foo:...
Bowrah asked 23/11, 2012 at 16:29
3
Solved
In C++20, we are now able to constrain the auto keyword to only be of a specific type. So if I had some code that looked like the following without any constraints:
auto something(){
return 1;
}
...
Hajji asked 1/11, 2021 at 18:21
1
Solved
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3255.html defines decay_copy as follows:
template<typename T>
std::decay_t<T> decay_copy(T&& v)
{
return std::forward&...
Sanitarian asked 26/10, 2021 at 19:39
1 Next >
© 2022 - 2025 — McMap. All rights reserved.