Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2006-09-05 14:59:01


Stephan Tolksdorf <andorxor_at_[hidden]> writes:

> Hi
>
> why doesn't shared_array allow the same conversions as shared_ptr, so that
>
> boost::shared_ptr<int> ip;
> boost::shared_ptr<const int> ip2(ip);
>
> is allowed, but not
>
> boost::shared_array<int> ip;
> boost::shared_array<const int> ip2(ip);

Probably because that particular case wasn't anticipated. It was
deemed important to prevent this:

struct B { int x; };
struct D : B { int y; };
boost::shared_array<D> p1(new D[20]);
boost::shared_array<B> p2(p1);
p2[1]; // oops!

> Is it safe to use shared_ptr's with arrays if one supplies an array
> deleter as a constructor argument?

Yeah, if you consider allowing my oops example to be "safe"...

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk