|
Boost Users : |
Subject: Re: [Boost-users] [multi_array] Why the precondition on assignment?
From: alfC (alfredo.correa_at_[hidden])
Date: 2009-02-24 22:25:05
On 24 Feb., 05:42, Peter Barker <newbar..._at_[hidden]> wrote:
> > I wonder if anyone can give me the rationale behind
> > boost::multi_index's assignment operator having the following
> > precondition:
> That meant to say boost::multi_array like the subject does!
I am not sure, but it seems that the idea was to avoid (surprise)
reallocation by all means. If the LHS has to change size that means
reallocation in the first place.
Looking at the development history it seems that the author avoided
reallocation by all means in the first versions of the library. Then
he later added the .resize method (which does reallocation) but the
assignment still follows the original prescription and that is why I
believe. I might be wrong or there might be other reasons. I would
like to know too, if that is the case.
Note that, in multidimensional arrays, reallocation and/or copying is
needed even if it shrinks in some directions (and not only at growing
as one dimensional arrays)
Regarding whether the current is the right design, I am not sure, on
one hand it makes sense for a multidimensional arrays to forbid resize
altogether, because in almost all cases, resize means reallocation and
copying which has the order of cost of copy-constructing a new
multiarray. On the other hand this restricted assignment doesn't
follow the standard (expected) semantics.
Regars,
Alfredo
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net