]>
Commit | Line | Data |
---|---|---|
e851aa17 | 1 | // { dg-do compile { target c++17 } } |
79f31e3d | 2 | // |
7adcbafe | 3 | // Copyright (C) 2019-2022 Free Software Foundation, Inc. |
79f31e3d ESR |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
8 | // Free Software Foundation; either version 3, or (at your option) | |
9 | // any later version. | |
10 | // | |
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | // | |
16 | // You should have received a copy of the GNU General Public License along | |
17 | // with this library; see the file COPYING3. If not see | |
18 | // <http://www.gnu.org/licenses/>. | |
19 | ||
20 | #include <array> | |
21 | ||
e851aa17 JW |
22 | #ifndef __cpp_lib_array_constexpr |
23 | # error "Feature test macro for array constexpr is missing in <array>" | |
40541efe | 24 | #elif __cpp_lib_array_constexpr < 201803L |
e851aa17 | 25 | # error "Feature test macro for array constexpr has wrong value in <array>" |
e851aa17 JW |
26 | #endif |
27 | ||
40541efe JW |
28 | // This test is compiled as C++17 because array::iterator is just a pointer, |
29 | // so always meets the C++20 constexpr iterator requirements, even in C++17. | |
30 | ||
79f31e3d ESR |
31 | constexpr int |
32 | test() | |
33 | { | |
34 | constexpr std::array<int, 3> a1{{1, 2, 3}}; | |
35 | static_assert(1 == *a1.begin()); | |
36 | auto n = a1[0] * a1[1]* a1[2]; | |
37 | static_assert(1 == *a1.cbegin()); | |
38 | ||
39 | std::array<int, 3> a2{{0, 0, 0}}; | |
d37c29f9 ESR |
40 | auto a1i = a1.begin(); |
41 | auto a1e = a1.end(); | |
42 | auto a2i = a2.begin(); | |
43 | while (a1i != a1e) | |
44 | *a2i++ = *a1i++; | |
79f31e3d ESR |
45 | |
46 | return n; | |
47 | } | |
48 | ||
49 | void | |
50 | run_test() | |
51 | { | |
52 | constexpr int n = test(); | |
53 | } |