This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: 1.1b: g++ won't make sets of some iterators


J H M Dassen <jdassen@wi.leidenuniv.nl> writes:

> G++ will not allow me to make sets of some kinds of iterators.  The following
> code illustrates this problem:

>     typedef list<int>                   SceneList;
>     typedef SceneList::const_iterator   ModelIndex;
>     typedef set<ModelIndex>             ModelSet;

> /usr/include/g++/stl_function.h:100: no match for `const __list_iterator<int,const int &,const int *> & < const __list_iterator<int,const int &,const int *> &'

It's complaining that it cannot compare two instances of ModelIndex,
which is correct, since no operator< is available for bidirectional
iterators like the ones of list and set, because they cannot be
implemented efficiently.  If you really need this set, you may provide
a comparison operator as an additional argument to template class set.

> Making "SceneList" a set also causes an error, but making it a
> vector causes everything to compile okay.

Of course, vector iterators are random-access iterators, that can be
compared.

-- 
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]