valarray_copy implementation question
Gabriel Dos Reis
gdr@integrable-solutions.net
Tue Nov 17 14:31:00 GMT 2009
On Tue, Nov 17, 2009 at 8:01 AM, Paolo Carlini <paolo.carlini@oracle.com> wrote:
> Paolo Carlini wrote:
>> Thanks Gaby, because in fact I'm finding the issue quite substantive,
>> isn't just about some strange corner cases: it's really about copying
>> all the source elements or just picking some depending on the
>> destination mask; it's about checking for overruns of the destination or
>> not. A big difference.
>>
> To better explain what I mean, the below snippet, perfectly legal as far
> as I can see and not triggering any memory error, would fail the third
> assert at runtime if we do implement the simple change suggested by
> Christian. Note, the alternate implementation passes the testcase, as
> current libstdc++ does.
>
> I'm wondering if shouldn't just keep the current implementation
> unchanged, besides adding to it a check that the destination is not
> overrun. But that is also debatable, given the usual
> performance-dictated design choices for valarray...
>
> Paolo.
>
> ///////////////////
>
> #include <valarray>
> #include <cassert>
>
> int main()
> {
> int n = 6;
>
> std::valarray<int> dest (n);
> std::valarray<bool> b (false, n);
> b[2] = b[4] = b[5] = true;
>
> std::valarray<int> src (3);
> src[0] = -1;
> src[1] = -2;
> src[2] = -3;
>
> dest[b] = src; // 0
>
> assert ( dest[0] == 0 );
> assert ( dest[1] == 0 );
> assert ( dest[2] == -1 );
> assert ( dest[3] == 0 );
> assert ( dest[4] == -2 );
> assert ( dest[5] == -3 );
> }
This is a good test -- and capture pretty well the issue.
>
>
More information about the Libstdc++
mailing list