]>
Commit | Line | Data |
---|---|---|
7adcbafe | 1 | // Copyright (C) 2020-2022 Free Software Foundation, Inc. |
bc464641 PP |
2 | // |
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) | |
7 | // any later version. | |
8 | ||
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. | |
13 | ||
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/>. | |
17 | ||
18 | // { dg-options "-std=gnu++2a" } | |
19 | // { dg-do run { target c++2a } } | |
20 | ||
21 | #include <algorithm> | |
22 | #include <testsuite_hooks.h> | |
23 | #include <testsuite_iterators.h> | |
24 | #include <list> | |
25 | ||
26 | using __gnu_test::test_container; | |
27 | using __gnu_test::test_range; | |
28 | using __gnu_test::input_iterator_wrapper; | |
29 | using __gnu_test::output_iterator_wrapper; | |
30 | using __gnu_test::forward_iterator_wrapper; | |
31 | ||
32 | namespace ranges = std::ranges; | |
33 | ||
34 | struct X | |
35 | { | |
36 | int i; | |
37 | }; | |
38 | ||
39 | void | |
40 | test01() | |
41 | { | |
42 | const int c[6] = { 17, 17, 17, 17, 17, 17 }; | |
43 | { | |
44 | X x[6]; | |
45 | VERIFY( ranges::fill(x, X{17}) == x+6 ); | |
46 | VERIFY( ranges::equal(x, c, {}, &X::i) ); | |
47 | } | |
48 | ||
49 | { | |
50 | char x[6]; | |
51 | VERIFY( ranges::fill(x, 17) == x+6 ); | |
52 | VERIFY( ranges::equal(x, c) ); | |
53 | } | |
54 | ||
55 | { | |
56 | X x[6]; | |
57 | test_container<X, forward_iterator_wrapper> cx(x); | |
58 | VERIFY( ranges::fill(cx, X{17}) == cx.end() ); | |
59 | VERIFY( ranges::equal(cx, c, {}, &X::i) ); | |
60 | } | |
61 | ||
62 | { | |
63 | int x[6]; | |
64 | test_range<int, output_iterator_wrapper> rx(x); | |
65 | VERIFY( ranges::fill(rx, 17) == rx.end() ); | |
66 | VERIFY( ranges::equal(x, c) ); | |
67 | } | |
68 | ||
69 | { | |
70 | std::list<int> list(6); | |
71 | ranges::fill(list, 17); | |
72 | VERIFY( ranges::equal(list, c) ); | |
73 | } | |
74 | } | |
75 | ||
76 | constexpr bool | |
77 | test02() | |
78 | { | |
79 | bool ok = true; | |
80 | int x[5]; | |
81 | ranges::fill(x, 17); | |
82 | for (auto v : x) | |
83 | ok &= v == 17; | |
84 | return ok; | |
85 | } | |
86 | ||
87 | int | |
88 | main() | |
89 | { | |
90 | test01(); | |
91 | static_assert(test02()); | |
92 | } |