Boost logo

Boost :

Subject: Re: [boost] [array] assignement operator
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2009-05-15 12:16:49


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.

> > 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.

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.


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