Is the void() in decltype(void()) an expression or is it a function type?

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

Is it possible to use function return type as an argument in declaration of another function in C++?

decltype (MyFunction_1) will give you the type of MyFunction_1 (i.e. the function type std::tuple<int, bool, double> ()), you need to emulate a function calling 1 (via adding ()) to get the return type (i.e. std::tuple<int, bool, double>), e.g. void MyFunction_2 (decltype (MyFunction_1()) &params); // ^^ 1 The expression is evaluated at compile-time, the function won’t … Read more

C++ decltype and parentheses – why?

It’s not an oversight. It’s interesting, that in Decltype and auto (revision 4) (N1705=04-0145) there is a statement: The decltype rules now explicitly state that decltype((e)) == decltype(e)(as suggested by EWG). But in Decltype (revision 6): proposed wording (N2115=06-018) one of the changes is Parenthesized-expression inside decltype is not considered to be an id-expression. There … Read more

C++11 lambda in decltype

You cannot use a lambda expression except by actually creating that object- that makes it impossible to pass to type deduction like decltype. Ironically, of course, the lambda return rules make it so that you CAN return lambdas from lambdas, as there are some situations in which the return type doesn’t have to be specified. … Read more