In this question, the asker has the following function:
template<typename ITER>
bool nextPermutation(ITER start, ITER end)
{
return nextPermutation(start, end, std::iterator_traits<ITER>::iterator_category());
}
Why isn’t a typename needed before the std::iterator_traits? I thought it was needed for nested types of a template, if the template is dependent on a template parameter itself? GCC seems to support my idea, as it doesn’t compile under both 4.3.4 and 4.5.1, demanding a typename. Even so, it still compiles just fine under both Visual Studio 2008 and 2010.
Is this just another Visual Studio extension/bug I don’t know about?
Or is it actually possible to deduce that iterator_category is either a type or a function because it’s followed by a pair of parenthesis ()? (See @DeadGM’s messages starting here.) So is this maybe actually a bug in GCC?
Doesn’t MSVC implement the late-parsing scheme? In such a scheme, the compiler isn’t dependent on
typename. It just stores all the token in between the template definition’s braces, and when the template is instantiated, it parses those tokens. Since it then knows what is and what is not a type, it will work withouttypename.But if the compiler doesn’t diagnose the missing
typenamewhen you instantiate the template, then it’s non-conforming.All that matters is whether the name is dependent and qualified. Whether or not the template could deduce itself that the name is always a type doesn’t matter. It might matter for the quality of error messages for missing
typenames though.FWIW, no it’s not possible to deduce anything about
iterator_categoryon a language level.