Boost logo

Boost :

From: Lois Goldthwaite (loisg_at_[hidden])
Date: 2000-06-13 11:13:52

Isn't the value_type supposed to be something which is passed by value? As
opposed to a reference, which would permit operations on the value in the
container? If I say

    const T t1;
    T t2 = t1;

isn't that legal?

[This is a separate issue from your comment about dereferenceable. I haven't
dug into the code for that, but the snippet does look a bit suspect.]


David Abrahams wrote:

> template <class T, class V, class D = boost::detail::empty_base>
> struct dereferenceable : D
> {
> V* operator->() const
> {
> return &*static_cast<const T&>(*this);
> }
> };
> Notice that the return type is V*: plain, unadorned V*.
> The standard quoth:
> [iterator traits is specialized] for pointers to const as:
> template<class T> struct iterator_traits<const T*> {
> typedef ptrdiff_t difference_type;
> typedef T value_type;
> typedef const T* pointer;
> typedef const T& reference;
> typedef random_access_iterator_tag iterator_category;
> };
> Notice that the value_type is plain, unadorned T. I guess that means that
> the standard library expects value_type, even for const iterators, to be
> non-const. Exhaustively searching the standard for reliance on this "fact"
> turns up nothing of any consequence (look at uninitialized_copy and decide
> for yourself). This means that when we create the following class:
> struct X : boost::random_access_iterator_helper<X, Y, std::ptrdiff_t, const
> Y* const Y&>
> {
> ...
> };
> We get an iterator through which we can access Y as non-const, but whose
> iterator_traits look just like the iterator_traits for const Y*. Problem?
> I guess there shouldn't be one, (since we can ask the user to pass const Y
> as the value_type) but I am not confident...
> I suppose we could change the interface to dereferenceable to take the
> pointer type instead of the value_type.
> -Dave
> ------------------------------------------------------------------------
> IT Professionals: Match your unique skills with the best IT projects at
> ------------------------------------------------------------------------

Boost list run by bdawes at, gregod at, cpdaniel at, john at