Boost logo

Boost Users :

From: Ronald Garcia (garcia_at_[hidden])
Date: 2007-01-23 17:13:04


On Jan 16, 2007, at 3:51 PM, Matthias Troyer wrote:

>
> On Jan 16, 2007, at 4:59 PM, Ronald Garcia wrote:
>
>> Hello Markus,
>>
>> On Jan 16, 2007, at 9:06 AM, Markus Werle wrote:
>>
>>> IMHO the behaviour of operator= for multi_array is a little bit
>>> broken.
>>> A lot of preconditions required:
>>
>> Indeed operator= for multi_array requires the sizes of the
>> multi_arrays to match, hence the assertions. The multi_array type is
>> not meant to automatically resize when assigned to. All resizing is
>> intentionally meant to be explicit.
>> For your application, you will need to resize your array prior to
>> assignment.
>
> This is awkward since it means that any class with a multi_array
> member cannot use the default operator= but needs to implement a
> special operator=. We just ran into a subtle bug with this because of
> the semantics of the valarray operator=, and I would strongly argue
> for an operator = that makes the semantics of
>
> A x = y;
>
> equivalent to
>
> A x;
> x = y;
>

Hi Matthias,

multi_array's operator=() was designed to behave in a manner
consistent with the other array objects provided by the library
(subarrays, views, multi_array_ref). In particular, assignment
between any of these other types requires that the dimensions of the
arrays match, and it performs an assignment to the analogous
locations in the array. I am loath to alter these semantics.

One possible approach, which I'm not completely happy with, is to
provide special behavior for default constructed multi_arrays. In
particular, assignment to a default-constructed multi_array would
cause it to resize during assignment. This would make such default-
constructed multi_arrays special.

Cheers,
ron


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