[[patch] valarray (was Re: valarray_copy implementation question)
Christian BRUEL
christian.bruel@st.com
Thu Nov 26 10:31:00 GMT 2009
> the issue is only whether it makes sense to allow for a right hand
data larger than that.
I don't understand why you see this as an issue. if you have 2 true
elements in the mask array, the elements in the source array (if bigger
than 2) will be after the first 2 selected will just be ignored.
so
myarray[mymask] += valarray<int>(3,2);
and
myarray[mymask] += valarray<int>(3,10);
with 2 true elements and myarray of size n
are equivalent because with the current implementation, but the former
one is legal is not the first one, so it could work, or not.
Best Regards
Christian
Paolo Carlini wrote:
> On 11/26/2009 08:51 AM, Christian BRUEL wrote:
>> and your assignment proposals:
>> myarray[mymask] += valarray<int>(3,0);
>> myarray[mymask] += valarray<int>(3,2);
>> are NOT guaranteed to work fine since you'd have the array to be of
>> size 10 and the argument array of size [0,2]. Note that the size of
>> myarray is really 10, it's not the number of true elements that only
>> determines the elements to which the operation will apply.
>>
>> But in anycase, the current trunk behavior of the testcase is
>> Segmentation fault (compile with -O0) which is obviously wrong.
>>
> For sure it doesn't segfault here. It works fine with no memory leaks or
> errors. And, note, I don't know about the details of the Standard, isn't
> my area, but with the aboe (that is, ..(3,0) for the first assignment
> and ..(3,2) for the second), the right hand member makes available
> exactly as many elements as are assigned to the left hand elements
> corresponding to true booleans, _M_sz, that is. As I see it, the issue
> is only whether it makes sense to allow for a right hand data larger
> than that, with some elements which end up not being used, that is not
> assigned to any left hand slot. I'm not sure whether this is correct,
> Gaby may know better.
>
> Paolo.
>
More information about the Libstdc++
mailing list