]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/26_numerics/exclusive_scan/1.cc
1 // { dg-options "-std=gnu++17" }
2 // { dg-do run { target c++17 } }
4 // Copyright (C) 2019-2021 Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
21 // C++17 29.8.7 [exclusive.scan]
25 #include <testsuite_hooks.h>
26 #include <testsuite_iterators.h>
28 int a
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
30 using __gnu_test::test_container
;
31 using __gnu_test::input_iterator_wrapper
;
32 using __gnu_test::output_iterator_wrapper
;
35 template<class InputIterator, class OutputIterator, class T>
37 exclusive_scan(InputIterator, InputIterator, OutputIterator, T);
43 test_container
<int, output_iterator_wrapper
> co(out
);
44 test_container
<int, input_iterator_wrapper
> ca(a
);
45 auto end
= std::exclusive_scan(ca
.begin(), ca
.end(), co
.begin(), 5);
46 static_assert(std::is_same_v
<decltype(end
), decltype(co
.begin())>);
47 VERIFY( end
.ptr
== out
+10 );
48 VERIFY( out
[0] == 5 );
49 VERIFY( out
[1] == 6 );
50 VERIFY( out
[2] == 8 );
51 VERIFY( out
[3] == 11 );
52 VERIFY( out
[4] == 15 );
53 VERIFY( out
[5] == 20 );
54 VERIFY( out
[6] == 26 );
55 VERIFY( out
[7] == 33 );
56 VERIFY( out
[8] == 41 );
57 VERIFY( out
[9] == 50 );
61 template<class InputIterator, class OutputIterator, class T,
62 class BinaryOperation>
64 exclusive_scan(InputIterator, InputIterator, OutputIterator, T,
71 test_container
<int, output_iterator_wrapper
> co(out
);
72 test_container
<int, input_iterator_wrapper
> ca(a
);
73 auto end
= std::exclusive_scan(ca
.begin(), ca
.end(), co
.begin(), 2,
74 [](int i
, int j
) { return 2*i
+ 2*j
; });
75 static_assert(std::is_same_v
<decltype(end
), decltype(co
.begin())>);
76 VERIFY( end
.ptr
== out
+10 );
77 VERIFY( out
[0] == 2 );
78 VERIFY( out
[1] == 6 );
79 VERIFY( out
[2] == 16 );
80 VERIFY( out
[3] == 38 );
81 VERIFY( out
[4] == 84 );
82 VERIFY( out
[5] == 178 );
83 VERIFY( out
[6] == 368 );
84 VERIFY( out
[7] == 750 );
85 VERIFY( out
[8] == 1516 );
86 VERIFY( out
[9] == 3050 );