Re: [gtkmm] A const_iterator for TreeModel?
- From: Robert Zeh <rzeh efs-us com>
- To: murrayc murrayc com
- Cc: gtkmm-list gnome org
- Subject: Re: [gtkmm] A const_iterator for TreeModel?
- Date: Tue, 17 Feb 2004 15:21:31 -0600
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.
What exactly did you try? This worked for me, with GNU 3.3.2 and
SunPro:
std::list<int> l;
std::list<int>::iterator bar(l.begin());
std::list<int>::const_iterator foo(bar);
///std::list<int>::iterator bar2(foo); /// Fails --- can't go
directly from const_iterator to iterator.
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?
Base() isn't terribly obscure; it's part of the standard, and mentioned
in Stroustrup.
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.
_______________________________________________
You're right. You should be able to just write:
foo(const_iterator)
And call it with
foo(iterator)
Of course, this assumes that everything you are doing now with an
iterator can
also be done with a const_iterator.
However, you'll still need to have another function definition for the
reverse_iterator's.
There are some corner cases in converting between reverse iterators and
forward
iterators.
Robert Zeh
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]