]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/26_numerics/valarray/83860.cc
1 // Copyright (C) 2018-2024 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-do run { target c++11 } }
21 #include <testsuite_hooks.h>
23 const std::valarray
<int> v
{
24 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
28 all_of(const std::valarray
<bool>& vals
)
40 const std::valarray
<int> va(v
), vb(v
), vc(v
);
41 auto sum
= va
+ vb
+ vc
;
42 std::valarray
<int> vsum
= sum
;
43 VERIFY( all_of( vsum
== (3 * v
) ) );
50 std::valarray
<int> vneg
= neg
;
51 VERIFY( all_of( vneg
== v
) );
57 const std::valarray
<int> va(v
), vb(v
);
59 std::valarray
<int> vdiff
= diff
;
60 VERIFY( all_of( vdiff
== (va
- vb
) ) );
66 const std::valarray
<int> va(v
), vb(v
);
68 std::valarray
<int> vsum
= sum
;
69 VERIFY( all_of( vsum
== (-2 * v
) ) );
75 const std::valarray
<int> va(v
), vb(v
);
76 auto sum
= -(-va
+ -vb
);
77 std::valarray
<int> vsum
= sum
;
78 VERIFY( all_of( vsum
== (2 * v
) ) );
84 auto prod
= 3 * +v
* 2;
85 std::valarray
<int> vprod
= prod
;
86 VERIFY( all_of( vprod
== (6 * v
) ) );
92 const std::valarray
<int> va(v
), vb(v
);
93 auto valfun
= [](int i
) { return i
; };
94 auto reffun
= [](const int& i
) { return i
; };
95 auto sum
= (va
.apply(valfun
) + vb
.apply(reffun
));
96 std::valarray
<int> vsum
= sum
;
97 VERIFY( all_of( vsum
== (va
+ vb
) ) );