This is a mouthful, so here’s a piece of code as an example:
template<typename T>
void foo(const T& a, typename T::value_type::value_type b) { }
std::vector<std::vector<int>> vec;
foo(vec, 4); // Error, can't specialize function template
This compiles and runs correctly using gcc. It doesn’t compile using Visual Studio 2010, for the reason commented above. However, if the final value_type is prefixed with the template keyword, it will compile and run correctly. I have a few guesses as to why, but can’t find the relevant section of the standard.
template<typename T>
void foo(const T& a, typename T::value_type::template value_type b) { }
std::vector<std::vector<int>> vec;
foo(vec, 4); // Compiles and runs correctly with Visual Studio 2010
I’m aware that the above usage of template is a Visual Studio extension, but what does the standard say about using types like this? Is gcc’s acceptance of the code also an extension, or is this a deficiency on Visual Studio’s part?
This is absolutely a deficiency on VC++ 2010’s part –
std::vector<int>::value_typeis a type, not a template, and should not be decorated as such. In fact, use of that syntax in this context should cause a compiler error.Supporting evidence is that the following does compile (as it should):
and the following doesn’t (as it shouldn’t):
The resulting error being
I recommend opening a bug report on MS Connect and posting the link back here so we can vote it up.