Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
312 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...