]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/experimental/array/make_array.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / array / make_array.cc
1 // { dg-do compile { target c++14 } }
2
3 // Copyright (C) 2015-2019 Free Software Foundation, Inc.
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 <experimental/array>
21 #include <functional> // for std::ref and std::reference_wrapper
22
23 struct MoveOnly
24 {
25 MoveOnly() = default;
26 MoveOnly(MoveOnly&&) = default;
27 MoveOnly& operator=(MoveOnly&&) = default;
28 };
29
30 void test01()
31 {
32 char x[42];
33 std::array<char, 42> y = std::experimental::to_array(x);
34 std::array<int, 5> z = std::experimental::make_array(1,2,3,4,5);
35 std::array<long, 3> zz = std::experimental::make_array(1,2L, 3);
36 std::array<MoveOnly, 1> zzz = std::experimental::make_array(MoveOnly{});
37 int dummy;
38 auto good = std::experimental::make_array<
39 std::reference_wrapper<int>>(std::ref(dummy));
40 constexpr char x2[42]{};
41 constexpr std::array<char, 42> y2 = std::experimental::to_array(x2);
42 constexpr std::array<int, 5> z2 =
43 std::experimental::make_array(1,2,3,4,5);
44 constexpr std::array<long, 3> zz2
45 = std::experimental::make_array(1,2L, 3);
46 constexpr std::array<MoveOnly, 1> zzz2 = std::experimental::make_array(MoveOnly{});
47 }
48
49 void test02()
50 {
51 // PR libstdc++/79195
52 struct A {};
53 struct B : A {};
54 struct C : A {};
55 auto arr = std::experimental::make_array<A>(B{}, C{});
56 static_assert(std::is_same<decltype(arr), std::array<A, 2>>::value, "");
57 }