]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/26_numerics/transform_inclusive_scan/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 26_numerics / transform_inclusive_scan / 1.cc
1 // { dg-options "-std=gnu++17" }
2 // { dg-do run { target c++17 } }
3
4 // Copyright (C) 2019-2020 Free Software Foundation, Inc.
5 //
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)
10 // any later version.
11
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.
16
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/>.
20
21 // C++17 29.8.10 [transform.inclusive.scan]
22
23 #include <numeric>
24 #include <iterator>
25 #include <testsuite_hooks.h>
26 #include <testsuite_iterators.h>
27
28 int a[] = {1, 2, 3, 4, 5, 6, 7};
29
30 using __gnu_test::test_container;
31 using __gnu_test::input_iterator_wrapper;
32 using __gnu_test::output_iterator_wrapper;
33
34 /*
35 template<class InputIterator, class OutputIterator, class BinaryOperation,
36 class UnaryOperation>
37 OutputIterator
38 transform_inclusive_scan(InputIterator, InputIterator, OutputIterator,
39 BinaryOperation, UnaryOperation);
40 */
41 void
42 test01()
43 {
44 int out[7];
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(),
48 std::multiplies<>(),
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) );
59 }
60
61 /*
62 template<class InputIterator, class OutputIterator, class BinaryOperation,
63 class UnaryOperation, class T>
64 OutputIterator
65 transform_inclusive_scan(InputIterator, InputIterator, OutputIterator,
66 BinaryOperation, UnaryOperation, T);
67 */
68 void
69 test02()
70 {
71 int out[7];
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(),
75 std::multiplies<>(),
76 [](int i) { return i+1; },
77 3);
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) );
87 }
88
89 int
90 main()
91 {
92 test01();
93 test02();
94 }