Pregunta

Consider these three statements:

std::map<int, std::string> foo;
std::map<int, std::string>::value_type;
decltype(foo)::value_type;

Why isn't the last one legal? I thought that decltype(foo) would be an operator yielding the map type std::map<int, std::string> from which I could extract the value_type.

I'm using MSVC2012.

¿Fue útil?

Solución

GCC and Clang allow this syntax, your compiler is failing at properly implementing C++11.

You can do this, though:

std::map<int, std::string> foo;
std::map<int, std::string>::value_type;
using some_type = decltype(foo);
some_type::value_type;

Otros consejos

Its valid, you have other errors, you must give a name to your variable:

std::map<int, std::string> foo;
std::map<int, std::string>::value_type nn_var;
decltype(foo)::value_type nn2_var;
typedef decltype(foo)::value_type value_type;

use:

std::remove_reference<decltype(foo)>::type::value_type
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top