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

In this question , the author of the question has the following function:

template<typename ITER> bool nextPermutation(ITER start, ITER end) { return nextPermutation(start, end, std::iterator_traits<ITER>::iterator_category()); } 

Why is typename not required before std::iterator_traits ? I thought it was necessary for nested template types if the template depends on the template parameter itself? GCC seems to support my idea as it does not compile under 4.3.4 and 4.5.1 , requiring typename . However, it still compiles just fine under Visual Studio 2008 and 2010.
Is this another Visual Studio extension / bug that I don't know about?
Or is it really possible to conclude that iterator_category is either a type or a function, because it is followed by a pair of brackets () ? (See @ DeadGM posts starting here .) So it could actually be a bug in GCC?

+6
source share
2 answers

Does MSVC implement a late parsing scheme? In such a scheme, the compiler is not dependent on typename . It simply stores all tokens between the template definition templates, and when an instance of the template is created, it analyzes these tokens. Since he then knows what is and what is not a type, it will work without typename .

But if the compiler does not diagnose the missing typename when instantiating the template, then it does not meet the requirements.

Or is it really possible to conclude that iterator_category is either a type or a function, because it is followed by a pair of brackets ()?

Everything that matters depends on whether the name is dependent and qualified. Regardless of whether the template can infer that the name is always a type, it does not matter. This may be important for the quality of error messages in the absence of typename .

FWIW, there is no conclusion about iterator_category at the language level.

+6
source

Visual C ++ is well known for not (fully) supporting two-phase search, which is the main reason why typename is required in the first place. If the compiler does not fully support this, it may not fully analyze the template before creating it, and by this time it “knows” that std::iterator_traits<ITER>::iterator_category is a type. Obviously, this flaw extends to the VC10.

When it comes to typename , I will trust GCC through VC any day.

+11
source

Source: https://habr.com/ru/post/886024/


All Articles