]>
Commit | Line | Data |
---|---|---|
83ffe9cd | 1 | // Copyright (C) 2019-2023 Free Software Foundation, Inc. |
3a66e68a ESR |
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 compile { target c++2a } } | |
20 | ||
21 | #include <algorithm> | |
22 | #include <array> | |
23 | ||
3a66e68a ESR |
24 | constexpr bool |
25 | test() | |
26 | { | |
27 | constexpr std::array<int, 12> ca0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}}; | |
28 | ||
29 | std::array<int, 12> ma0{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; | |
30 | const auto out7 = std::copy_backward(ca0.begin(), ca0.begin() + 8, | |
31 | ma0.begin() + 10); | |
32 | ||
8c84486b | 33 | return out7 == ma0.begin() + 2 && ma0[3] == 1; |
3a66e68a ESR |
34 | } |
35 | ||
36 | static_assert(test()); | |
490350a1 JW |
37 | |
38 | constexpr bool | |
39 | test02() | |
40 | { | |
41 | struct X | |
42 | { | |
43 | X() = default; | |
44 | X& operator=(const X&) = default; | |
45 | constexpr X& operator=(X&& x) { i = x.i; x.i = 0; return *this; } | |
46 | int i = 1; | |
47 | }; | |
48 | ||
49 | X from[1], to[1]; | |
50 | std::copy_backward(std::begin(from), std::end(from), std::end(to)); | |
51 | return from[0].i == 1; | |
52 | } | |
53 | ||
54 | static_assert(test02()); | |
815eb852 FD |
55 | |
56 | constexpr bool | |
57 | test03() | |
58 | { | |
59 | std::array<int, 12> ma0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}}; | |
60 | const auto out7 = std::copy_backward(ma0.begin(), ma0.begin() + 8, | |
61 | ma0.begin() + 10); | |
62 | ||
63 | return out7 == ma0.begin() + 2 && *out7 == 0 && *(ma0.begin() + 9) == 7; | |
64 | } | |
65 | ||
66 | static_assert(test03()); |