What does auto&& tell us?

By using auto&& var = <initializer> you are saying: I will accept any initializer regardless of whether it is an lvalue or rvalue expression and I will preserve its constness. This is typically used for forwarding (usually with T&&). The reason this works is because a “universal reference”, auto&& or T&&, will bind to anything. … Read more

How does generic lambda work in C++14?

Generic lambdas were introduced in C++14. Simply, the closure type defined by the lambda expression will have a templated call operator rather than the regular, non-template call operator of C++11‘s lambdas (of course, when auto appears at least once in the parameter list). So your example: auto glambda = [] (auto a) { return a; … Read more

Should the trailing return type syntax style become the default for new C++11 programs? [closed]

There are certain cases where you must use a trailing return type. Most notably, a lambda return type, if specified, must be specified via a trailing return type. Also, if your return type utilizes a decltype that requires that the argument names are in scope, a trailing return type must be used (however, one can … Read more

What is the type of lambda when deduced with “auto” in C++11?

The type of a lambda expression is unspecified. But they are generally mere syntactic sugar for functors. A lambda is translated directly into a functor. Anything inside the [] are turned into constructor parameters and members of the functor object, and the parameters inside () are turned into parameters for the functor’s operator(). A lambda … Read more

How much is too much with C++11 auto keyword?

I think that one should use the auto keyword whenever it’s hard to say how to write the type at first sight, but the type of the right hand side of an expression is obvious. For example, using: my_multi_type::nth_index<2>::type::key_type::composite_key_type:: key_extractor_tuple::tail_type::head_type::result_type to get the composite key type in boost::multi_index, even though you know that it is … Read more

tech