Why is typename _not_ needed here in Visual Studio 2008/2010?

前端 未结 2 674
抹茶落季
抹茶落季 2020-12-19 08:45

In this question, the asker has the following function:

template
bool nextPermutation(ITER start, ITER end)
{
    return nextPermutation         


        
相关标签:
2条回答
  • 2020-12-19 09:11

    Visual C++ is well-known not to (fully) support two-phase lookup, which is the underlying reason for why typename is required in the first place. If the compiler doesn't fully support this, it might not fully parse a template before it is instantiated, by which time it "knows" that std::iterator_traits<ITER>::iterator_category is a type. Obviously, this deficiency extends to VC10.

    When it comes to typename, I'd trust GCC over VC any day.

    0 讨论(0)
  • 2020-12-19 09:14

    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 without typename.

    But if the compiler doesn't diagnose the missing typename when you instantiate the template, then it's non-conforming.

    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 ()?

    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_category on a language level.

    0 讨论(0)
提交回复
热议问题