Re: [gtkmm] A const_iterator for TreeModel?



Murray Cumming wrote:

I was half-way through implementing the const_iterator,
reverse_iterator, and const_reverse_iterator for TreeModel:
http://bugzilla.gnome.org/show_bug.cgi?id=134520

Then I released that, even with a std::list, you can't do
 std::list::iterator iter_non_const;
 std::list::const_iterator iter_const = iter_non_const;
either explicitly or implicitly.

But you would want to use them in almost all the same places, so any
 do_something(const iterator& iter);
method would need
 do_something(const const_iterator& iter);
and
 do_something(const reverse_iterator& iter);
 do_something(const const_reverse_iterator& iter);

And that would get ridiculous quite quickly, and really problematic when
dealing with virtual methods that should be overridden. Am I
misunderstanding something? I can't think of a good example in the
standard C++ library - things like std::find are templates.

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!.  You have to use the base() method on
the reverse iterators to get to iterators.

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.

Robert Zeh




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