Friday, 13 September 2013

Is {1, 2} a value? If yes, what is its type? If no, why can it be assigned to an initializer list?

Is {1, 2} a value? If yes, what is its type? If no, why can it be assigned
to an initializer list?

#include <initializer_list>
using namespace std;
template<class T>
void f(initializer_list<T>)
{}
int main()
{
typeid(1); // OK
typeid(int); // OK
typeid(decltype(1)); // OK
f({1, 2}); // OK
typeid({1, 2}); // error
decltype({1, 2}) v; // error
typeid(decltype({1, 2})); // error
}
Is {1, 2} a value?
If yes, why is typeid({1, 2}); not legal?
If no, why can it be assigned to an initializer_list object?

No comments:

Post a Comment