]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/26_numerics/transform_inclusive_scan/1.cc
1 // { dg-options "-std=gnu++17" }
2 // { dg-do run { target c++17 } }
4 // Copyright (C) 2019-2020 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.10 [transform.inclusive.scan]
25 #include <testsuite_hooks.h>
26 #include <testsuite_iterators.h>
28 int a
[] = {1, 2, 3, 4, 5, 6, 7};
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 BinaryOperation,
38 transform_inclusive_scan(InputIterator, InputIterator, OutputIterator,
39 BinaryOperation, UnaryOperation);
45 test_container
<int, output_iterator_wrapper
> co(out
);
46 test_container
<int, input_iterator_wrapper
> ca(a
);
47 auto end
= std::transform_inclusive_scan(ca
.begin(), ca
.end(), co
.begin(),
49 [](int i
) { return i
+1; });
50 static_assert(std::is_same_v
<decltype(end
), decltype(co
.begin())>);
51 VERIFY( end
.ptr
== out
+7 );
52 VERIFY( out
[0] == 2 );
53 VERIFY( out
[1] == (2*3) );
54 VERIFY( out
[2] == (2*3*4) );
55 VERIFY( out
[3] == (2*3*4*5) );
56 VERIFY( out
[4] == (2*3*4*5*6) );
57 VERIFY( out
[5] == (2*3*4*5*6*7) );
58 VERIFY( out
[6] == (2*3*4*5*6*7*8) );
62 template<class InputIterator, class OutputIterator, class BinaryOperation,
63 class UnaryOperation, class T>
65 transform_inclusive_scan(InputIterator, InputIterator, OutputIterator,
66 BinaryOperation, UnaryOperation, T);
72 test_container
<int, output_iterator_wrapper
> co(out
);
73 test_container
<int, input_iterator_wrapper
> ca(a
);
74 auto end
= std::transform_inclusive_scan(ca
.begin(), ca
.end(), co
.begin(),
76 [](int i
) { return i
+1; },
78 static_assert(std::is_same_v
<decltype(end
), decltype(co
.begin())>);
79 VERIFY( end
.ptr
== out
+7 );
80 VERIFY( out
[0] == 3*2 );
81 VERIFY( out
[1] == (3*2*3) );
82 VERIFY( out
[2] == (3*2*3*4) );
83 VERIFY( out
[3] == (3*2*3*4*5) );
84 VERIFY( out
[4] == (3*2*3*4*5*6) );
85 VERIFY( out
[5] == (3*2*3*4*5*6*7) );
86 VERIFY( out
[6] == (3*2*3*4*5*6*7*8) );