Topic: No typename preceding concept-related dependent names


Author: Scott Meyers <usenet@aristeia.com>
Date: Sat, 30 May 2009 12:05:24 CST
Raw View
C++03 specifies count like this:

template<class InputIterator, class T>
typename iterator_traits<InputIterator>::difference_type
count(InputIterator first, InputIterator last, const T& value);

In the return type, difference_type is a dependent name, hence the
preceding
"typename."

The C++0x working draft (N2857) specifies count this way:

template<InputIterator Iter, class T>
requires HasEqualTo<Iter::value_type, T>
Iter::difference_type count(Iter first, Iter last, const T& value);

Iter::difference_type looks like a dependent name to me, but there's no
preceding "typename".  The same thing appears elsewhere in the working
draft,
including in parameter lists,

template<InputIterator InIter, OutputIterator<auto, InIter::reference>
OutIter>
OutIter copy_n(InIter first, InIter::difference_type n,
OutIter result);

so I'm sure this isn't a typo.

I suspect this is a concept-related thing, but I'm not sure.  Can somebody
please explain why typename is not needed in these cases?

Thanks,

Scott


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Sean Hunt <rideau3@gmail.com>
Date: Sat, 30 May 2009 12:47:08 CST
Raw View
On May 30, 12:05 pm, Scott Meyers <use...@aristeia.com> wrote:
> I suspect this is a concept-related thing, but I'm not sure.  Can somebody
> please explain why typename is not needed in these cases?
It is concept-related. Because the concept specifies that there exists
a type "difference_type", the compiler can look it up in the Iterator
concept and say "oh, I don't know what that's going to be, but it's
certainly going to be a type" and parse accordingly. Concepts provide
a tool for removing the ambiguity that could otherwise be present.

Sean


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]