Boost logo

Boost :

Subject: Re: [boost] [Pointer Container] Modification of pointer containers to allow const elements
From: Gerardo Hernandez (g.hernandez_at_[hidden])
Date: 2010-10-15 16:04:44

2010/10/15 John Bytheway <jbytheway+boost_at_[hidden]>:
> I presume that Scott only intended to suggest abandoning
> const-correctness in the implementation, not the interface.  Thus the
> above assignment would still cause an error.  Since type safety has
> already been abandoned by making all pointers void*, const-correctness
> doesn't seem much of an additional sacrifice.

I see the point. But I do not understand the advantage of using a
single underlying type instead of two (which I presume was also
Thorsten idea). Using always void* would not only require a lot of
const_cast when returning data from the containers but also think that
ptr_vector<T>::iterator must be of different type as ptr_vector<const
T>::iterator, as:

boost::ptr_vector<const int> v;
v.push_back(new int);
(*v.begin()) = 2;

shall also be compiler error, as the container contains const elements.

To sum up I think it is best to use the metafunction when
instantiating the underlying type, as the implementation is simpler.

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