]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/array/creation/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / array / creation / 1.cc
1 // { dg-options "-std=gnu++2a" }
2 // { dg-do compile { target c++2a } }
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 #include <array>
22
23 #ifndef __cpp_lib_to_array
24 # error "Feature test macro for to_array is missing"
25 #elif __cpp_lib_to_array < 201907L
26 # error "Feature test macro for to_array has wrong value"
27 #endif
28
29 void test01()
30 {
31 const char x[6]{};
32 std::array<char, 6> y = std::to_array(x);
33
34 constexpr char x2[] = "foo";
35 constexpr std::array<char, 4> y2 = std::to_array(x2);
36 static_assert( std::equal(y2.begin(), y2.end(), x2) );
37 }
38
39 void
40 test02()
41 {
42 struct MoveOnly
43 {
44 constexpr MoveOnly(int i = 0) : i(i) { }
45 constexpr MoveOnly(MoveOnly&& m) : i(m.i + 100) { }
46 int i;
47 };
48
49 struct X {
50 MoveOnly m[3];
51 };
52 X x;
53 std::array<MoveOnly, 3> y = std::to_array(std::move(x).m);
54
55 constexpr std::array<MoveOnly, 3> y2 = std::to_array(X{{1, 2, 3}}.m);
56 static_assert( y2[0].i == 101 && y2[1].i == 102 && y2[2].i == 103 );
57 }