Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-01-11 13:14:25


From: "Andrei Alexandrescu" <andrewalex_at_[hidden]>
> > I find the idea of enabling pointer arithmetic for shared_array somewhat
> > questionable, but...
> >
> > shared_array in
> >
> > http://groups.yahoo.com/group/boost/files/smart_ptr_3.zip
> >
> > can be trivially extended to support it by adding
> >
> > shared_array & operator+= (std::ptrdiff_t i)
> > {
> > px += i;
> > return *this;
> > }
> >
> > Of course the BOOST_ASSERT(i >= 0); in operator[] will need to be
removed.
>
> But this operation is nonsensical in most, if not all, cases. Why would
> someone need to alter a shared_array? It doesn't make sense; it means that
> either before, or after the operation, the pointee array will be wrong.
>
> I guess only operator+(int), operator-(int) should be allowed as pointer
> arithmetic - if at all. operator-(T*) or operator-(sharte_array&) don't
make
> much sense, either.

I find the whole idea of adding pointer arithmetic to shared_array
questionable at best and nonsensical at worst.

That said, if I had to support pointer arithmetic, I'd rather provide the
full range of operators.

--
Peter Dimov
Multi Media Ltd.

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