Boost logo

Boost :

Subject: Re: [boost] [array] assignement operator
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2009-05-18 19:39:50


----- Original Message -----
From: "Stewart, Robert" <Robert.Stewart_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Friday, May 15, 2009 6:16 PM
Subject: Re: [boost] [array] assignement operator

>
> vicente.botet wrote:
> On Friday, May 15, 2009 11:46 AM
>>
>> Is the following more intuitive?
>>
>> array<int,10> a;
>> array<int, 5> b;
>>
>> as_sub_array<0,4>(a) = b;
>> // or
>> b=as_sub_array<2,6>(a);
>
> I like that idea, though I'd name it "subarray." I'd expect these to fail at compile time:
>
> subarray<0,4>(a) = b;
> b = subarray<0,4>;
>
> but not these:
>
> subarray<0,5>(a) = b;
> b = subarray<0,5>(a);
>
> Thus, I see subarray as having its size specified by the second template parameter and the offset into the array as the first template parameter.
>
> This should also be possible:
>
> subarray<6,3>(a) = subarray<1,3>(b);
>
> Notice how the "3" matches in that statement, clearly showing that the two subarrays have the same length.

Yeah, this is clear. We can have a class 'subarray_view' and a factory function 'subarray'. subarray_view is a kind of static range.
 
>> > The suggested idea may have its uses, but it has
>> sufficiently odd behavior that it ought not to be a member
>> function and certainly not the copy assignment operator.
>> Perhaps a free function is in order.
>>
>> Do you think that an specialization of a assign_to function
>> would be intuitive
>>
>> array<int, 5> a;
>> array<int, 2> b;
>> // ...
>> assign_to(b,a);
>> // or
>>
>> assign_to(b,as_sub_array<0,1>a);
>
> I don't like that. The argument order isn't intuitive and the odd behavior isn't made clear by the name. Besides, I think subarray handles every use case and makes the subset assignment behavior clear.

You are right, in order to have

    b = subarray<0,5>(a);

efficient we need to overload the assignement operator on the array class.

If no modification is made on the array class an 'assign' function can always be implemented efficiently.

    assign(b,subarray<0,5>(a));

Thanks,
Vicente


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