Re: [gtkmm] A const_iterator for TreeModel?
- From: Carl Nygard <cjnygard fast net>
- To: Murray Cumming <murrayc murrayc com>
- Cc: gtkmm-list <gtkmm-list gnome org>
- Subject: Re: [gtkmm] A const_iterator for TreeModel?
- Date: Tue, 17 Feb 2004 00:56:16 -0500
On Mon, 2004-02-16 at 11:31, 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);
Is this a theoretical complaint or do you have a specific case in mind?
I look at some_func(iterator/const_iterator) the same way as
some_func(Foo&/const Foo&). You're either going to have one or the
other, depending on whether you modify the argument or not.
I can see that you may have an iterator that you want to pass to a
function, and you'd want iterator->const_iterator promotion implicitly,
but not the other way round.
The bits/stl_iterator.h shows this:
// Allow iterator to const_iterator conversion
template<typename _Iter>
inline __normal_iterator(const __normal_iterator<_Iter,
_Container>& __i)
: _M_current(__i.base()) { }
So with a template ctor you can get the iterator->const_iterator
promotion. The const_iterator->iterator conversion is disallowed
because the underlying ptr types (this is for promoting ptrs to
iterators) aren't assignable because of the const-ness.
I don't know specifically about std::list::(const_)iterator, but the
stl_iterator.h seems to indicate this operation should be
implemented(able).
Regards,
Carl
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]