This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Iterator over a map of generic vectors.
- From: "Eric Lance" <eric dot lance at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 8 Sep 2006 16:28:47 -0600
- Subject: Iterator over a map of generic vectors.
Hi all,
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
}
On GCC 4.1.0 (Suse) and GCC 3.4.4 (FreeBSD) it throws the following
syntax error:
Test.cpp: In function 'void func()':
Test.cpp:16: error: expected `;' before 'i'
The code snippet will compile cleanly on MS visual studio. It also
seems illogical that I can declare map "m", but it is illegal to
declare the iterator " i". So, is this a "feature" or a bug?
I'm not subscribed to the list, so please CC me in on any replies.
Thanks,
Eric
PS As a workaround, I changed the declaration to the following, which
seems to work:
typeof(m.iterator) i=m.begin();