This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Iterator over a map of generic vectors.
- From: David Fang <fang at csl dot cornell dot edu>
- To: Eric Lance <eric dot lance at gmail dot com>, Ian Lance Taylor <iant at google dot com>
- Cc: <gcc-help at gcc dot gnu dot org>
- Date: Mon, 11 Sep 2006 12:38:49 -0400 (EDT)
- Subject: Re: Iterator over a map of generic vectors.
Greets,
Before people get too confused here by tangential topics, I'd just
like to reiterate that Ian already answered the original question on 9/8,
simply: that an (template) argument-dependent nested type (e.g. map<int,
vector<T> >::iterator) requires the 'typename' keyword prefixed.
(Earlier compiler versions didn't require it, a.k.a. implicit typenames,
which is non-standard conforming.)
See first bullet under: http://gcc.gnu.org/bugs.html#nonbugs_cxx
The original posted code (below) has nothing to do with template
argument deduction, as was alluded and mentioned in another response.
> "Eric Lance" <eric.lance@gmail.com> writes:
>
> > I'm trying to figure out if this is a bug or "feature". In a generic
> > function, I want to declare an iterator over a map whose values are
> > generic vectors. However, I get a syntax error whenever I try to
> > declare this particular kind of iterator. The code snippet below
> > should illustrate what I mean better:
> >
> > template<typename T>
> > void func()
> > {
> > map< int, vector<T> > m; //we want an iterator over m.
> > map< int, vector<T> >::iterator i; //this doesn't compile
> > map< int, vector<int> >::iterator k; //but this does
> > }
>
> This is not a gcc question. In standard C++ you need to say
> typename map< int, vector<T> >::iterator i;
Fang