Bra*_*don 5 c++ visual-c++ c++11
在我使用了一些模板代码中的一些错误后,std::vector::value_type我把它跟踪到以下内容.这是根据标准的正确行为,还是这是MSVC 2012 CTP的问题?
typedef std::vector<int>::value_type t1;
typedef std::vector<int const>::value_type t2;
static_assert(!std::is_same<t1, t2>::value, "hmmm");
Run Code Online (Sandbox Code Playgroud)
上述断言失败了.
所述value_type的一个std::vector<T>是T(§23.3.6.1).
is_same考虑cv限定符的值(第20.9.6节).
在你的情况下,这意味着检查std::is_same<int, int const>,这应该是失败的.
这反过来意味着您根据标准观察到的行为是错误的.似乎MSVC正在为value_type删除cv限定符:
std::vector<const int>::value_type val = 5;
val = 10;
Run Code Online (Sandbox Code Playgroud)
这在MSVC2008上编译但在gcc 4.4中失败.
您应该向Microsoft提交错误报告.
编辑:纳瓦兹上面的评论让我思考.根据这个问题 const int确实不容许在C AA VALUE_TYPE ++ 03!
看起来虽然它是在C++ 11中..虽然在C++ 11中没有明确禁止向量,但禁止使用分配器(第17.6.3.5节),这反过来又使得向量也是非法的.
无论如何,MSVC的行为默默地放弃了const这里似乎是错误的.