Re: [gtkmm] A const_iterator for TreeModel?



On Tue, 2004-02-17 at 13:40, murrayc murrayc com wrote:
> > Take a look at Item 26 in Scott Meyer's Effective STL.  He says that
> > there is an implicit conversion from iterator to const_iterator
> > --- but not the other way around!.
> 
> Interesting. I had tried that with std::list_iterator and const_iterator,
> without success. Could someone else try as well please.
> 

Works for me.  I tried something a bit more involved than rzeh.

> >  You have to use the base() method on
> > the reverse iterators to get to iterators.
> 
> Thanks. I didn't know that. Is that something that people are used to
> using, or is it an obscure part of the implementation?

Standard part.  Also used in Meyers (M)EC++ specifically for converting
between forward and reverse iterators, IIRC.
> 
> > So, you should be able to write a definitive const_iterator method,
> > and then have the other three call the const_iterator method
> > with the appropriate implicit or explicit conversion.
> 
> If there is _an_ implicit conversion then we should not need the other
> method overloads.

Right.  And if you want to deal with reverse_iterator without
duplicating code, I think you need to make it a template function.  But
that might lead to code bloat b/c then you have functions instantiated
for iterators as well as const_iterators.

Why exactly do you need to support reverse in function arguments?  If
you look at std::list, any iterator arg that points to its own members
is type 'iterator', but any iterator of an external collection is
templatized on the iterator type.

Regards,
Carl




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]