Using the type name nested in a template parameter

This is a sip, so here is a sample code:

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

It compiles and runs correctly using gcc. It does not compile using Visual Studio 2010 for the reason described above. However, if the final one value_typehas a prefix with a keyword template, it will compile and run correctly. I have a few guesses about why, but I can’t find the corresponding 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 know that the above use templateis a Visual Studio extension, but what does the standard say about using these types? Is gcc code adoption also an extension, or is it a flaw in the Visual Studio part?

+5
1

V++ 2010 part – std::vector<int>::value_type - , . , .

, ( ):

#include <vector>

template<typename T>
void foo(T const& a)
{
    typename T::value_type::value_type bar = a.at(0).at(0);
}

int main()
{
    std::vector<std::vector<int>> vec;
    foo(vec);
}

( ):

template<typename T>
void foo(T const& a)
{
    typename T::value_type::template value_type bar = a.at(0).at(0);
}

C2903: 'value_type': ,

MS Connect , .

+4

All Articles