|
Boost Users : |
From: David Abrahams (dave_at_[hidden])
Date: 2004-12-04 14:53:47
Tobias Schwinger wrote:
> Hi,
>
> While using boost::iterator_facade wirh a class type as argument for
> both the 'Reference' and the 'Value' template type parameter I noticed
> that I can't access non-const members via operator->.
Surely you can! You must mean that you can't modify members via
operator-> ?
> *i is not const
> and neither 'Value' nor 'Reference' are.
>
> A naiv look at the source shows me that
> operator_arrow_proxy::operator->() always returns 'T const *'.
>
> Is this a bug or an intentional restriction ?
It's intentional. When your iterator's reference type is not
value_type& or value_type const&, your reference type is the same as the
value_type or you are using a proxy reference. Either way, if your
iterator is readable, the reference is implicitly convertible to
value_type. If your iterator is writable, it can be assigned from the
value_type. No persistent object (lvalue) of type value_type is
revealed by dereferencing the iterator; you can at best see a temporary.
If iterator_facde handed you a pointer to non-const value_type, it
would allow you to modify this temporary, which would then disappear.
We don't do that for the same reasons the language won't bind a
non-const reference to a temporary.
-- Dave Abrahams Boost Consulting http://www.boost-consulting.com
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net