1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <array>
10 // UNSUPPORTED: c++03, c++11, c++14
11 
12 // template <class T, class... U>
13 //   array(T, U...) -> array<T, 1 + sizeof...(U)>;
14 //
15 //  Requires: (is_same_v<T, U> && ...) is true. Otherwise the program is ill-formed.
16 
17 #include <array>
18 #include <cassert>
19 #include <cstddef>
20 
21 // std::array is explicitly allowed to be initialized with A a = { init-list };.
22 // Disable the missing braces warning for this reason.
23 #include "disable_missing_braces_warning.h"
24 
25 #include "test_macros.h"
26 
27 constexpr bool tests()
28 {
29     //  Test the explicit deduction guides
30     {
31         std::array arr{1,2,3};  // array(T, U...)
32         static_assert(std::is_same_v<decltype(arr), std::array<int, 3>>, "");
33         assert(arr[0] == 1);
34         assert(arr[1] == 2);
35         assert(arr[2] == 3);
36     }
37 
38     {
39         const long l1 = 42;
40         std::array arr{1L, 4L, 9L, l1}; // array(T, U...)
41         static_assert(std::is_same_v<decltype(arr)::value_type, long>, "");
42         static_assert(arr.size() == 4, "");
43         assert(arr[0] == 1);
44         assert(arr[1] == 4);
45         assert(arr[2] == 9);
46         assert(arr[3] == l1);
47     }
48 
49     //  Test the implicit deduction guides
50     {
51         std::array<double, 2> source = {4.0, 5.0};
52         std::array arr(source);   // array(array)
53         static_assert(std::is_same_v<decltype(arr), decltype(source)>, "");
54         static_assert(std::is_same_v<decltype(arr), std::array<double, 2>>, "");
55         assert(arr[0] == 4.0);
56         assert(arr[1] == 5.0);
57     }
58 
59     return true;
60 }
61 
62 int main(int, char**)
63 {
64     tests();
65     static_assert(tests(), "");
66     return 0;
67 }
68