在std :: map中使用decltype

P45*_*ent 2 c++ decltype c++11

考虑这三个陈述:

std::map<int, std::string> foo;
std::map<int, std::string>::value_type;
decltype(foo)::value_type;
Run Code Online (Sandbox Code Playgroud)

为什么最后一个合法?我认为这decltype(foo)将是一个运算符,产生std::map<int, std::string>我可以从中提取的地图类型value_type.

我正在使用MSVC2012.

rub*_*nvb 5

GCC和Clang允许这种语法,你的编译器无法正确实现C++ 11.

但是你可以这样做:

std::map<int, std::string> foo;
std::map<int, std::string>::value_type;
using some_type = decltype(foo);
some_type::value_type;
Run Code Online (Sandbox Code Playgroud)