
The ability to assign a shared_ptr<T> to shared_ptr<const T> is useful
for controlling which parts of software have write access to the shared
object, so I'm surprised that while e.g
boost::shared_ptr<int> sp(new int);
boost::shared_ptr<const int> csp=sp;
compiles fine, and prohibits e.g *csp=0;, the equivalent for
shared_array doesn't compile:
boost::shared_array<int> sa(new int[10]);
boost::shared_array<const int> csa=sa; // not allowed
[The gcc 4.1.2 error is "conversion from ‘boost::shared_array<int>’ to
non-scalar type ‘boost::shared_array<const int>’ requested"]
I'm looking to prevent modification of elements of csa of course.
The obvious alternative is to use a shared_ptr to a std::vector of
course:
boost::shared_ptr