]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/26_numerics/reduce/2.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 26_numerics / reduce / 2.cc
1 // { dg-options "-std=gnu++17" }
2 // { dg-do compile { 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.3 [reduce]
22
23 #include <numeric>
24 #include <iterator>
25 #include <testsuite_hooks.h>
26 #include <testsuite_iterators.h>
27
28 struct T
29 {
30 T(int);
31 T(T&&); // MoveConstructible
32 T& operator=(T&&); // not required by the standard, but it needs to be
33 T operator+(const T&) const;
34 };
35
36 void
37 test01()
38 {
39 T t[1]{1};
40 std::reduce(t, t+1, T(0));
41
42 using __gnu_test::test_container;
43 using __gnu_test::input_iterator_wrapper;
44 test_container<T, input_iterator_wrapper> con(t);
45 std::reduce(con.begin(), con.end(), T(0));
46 }
47
48 struct Op
49 {
50 T operator()(T&, T&) const&;
51
52 // The standard does *not* require invoking as an rvalue to be supported.
53 T operator()(T&, T&) && = delete;
54
55 // The standard does *not* require rvalue arguments to be supported
56 // (this is almost certainly a defect and should be allowed).
57 T operator()(T&&, T&&) const = delete;
58 };
59
60 void
61 test02()
62 {
63 T t[1]{1};
64 std::reduce(t, t+1, T(0), Op());
65
66 using __gnu_test::test_container;
67 using __gnu_test::input_iterator_wrapper;
68 test_container<T, input_iterator_wrapper> con(t);
69 std::reduce(con.begin(), con.end(), T(0), Op());
70 }