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

前端 未结 2 680
抹茶落季
抹茶落季 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: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.

提交回复
热议问题