What does the void() in decltype(void()) mean exactly?

Using a hyperlinked C++ grammar, the parsing of decltype(void()) is: decltype( expression ) decltype( assignment-expression ) decltype( conditional-expression ) … lots of steps involving order of operations go here … decltype( postfix-expression ) decltype( simple-type-specifier ( expression-listopt ) ) decltype( void() ) So void() is a kind of expression here, in particular a postfix-expression. Specifically, … Read more

trailing return type using decltype with a variadic template function

I think the problem is that the variadic function template is only considered declared after you specified its return type so that sum in decltype can never refer to the variadic function template itself. But I’m not sure whether this is a GCC bug or C++0x simply doesn’t allow this. My guess is that C++0x … Read more

Arrow operator (->) in function heading

In C++11, there are two syntaxes for function declaration:     return-type identifier ( argument-declarations… ) and     auto identifier ( argument-declarations… ) -> return_type They are equivalent. Now when they are equivalent, why do you ever want to use the latter? Well, C++11 introduced this cool decltype thing that lets you describe type of an expression. So … Read more

decltype and parentheses

Just above that example, it says if e is an unparenthesized id-expression or a class member access (5.2.5), decltype(e) is the type of the entity named by e. if e is an lvalue, decltype(e) is T&, where T is the type of e; I think decltype(a->x) is an example of the “class member access” and … Read more

What expressions yield a reference type when decltype is applied to them?

It is not easy to understand these concepts without getting formal. The primer probably does not want to confuse you and avoids introducing terms such as “lvalue“, “rvalue“, and “xvalue“. Unfortunately, these are fundamental in order to understand how decltype works. First of all, the type of an evaluated expression is never a reference type, … Read more

tech