1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <array>
11 // UNSUPPORTED: c++98, c++03, c++11, c++14
12 // UNSUPPORTED: libcpp-no-deduction-guides
13 
14 
15 // template <class T, class... U>
16 //   array(T, U...) -> array<T, 1 + sizeof...(U)>;
17 //
18 //  Requires: (is_same_v<T, U> && ...) is true. Otherwise the program is ill-formed.
19 
20 
21 #include <array>
22 #include <cassert>
23 #include <cstddef>
24 
25 // std::array is explicitly allowed to be initialized with A a = { init-list };.
26 // Disable the missing braces warning for this reason.
27 #include "disable_missing_braces_warning.h"
28 
29 #include "test_macros.h"
30 
31 int main()
32 {
33 //  Test the explicit deduction guides
34     {
35     std::array arr{1,2,3};  // array(T, U...)
36     static_assert(std::is_same_v<decltype(arr), std::array<int, 3>>, "");
37     assert(arr[0] == 1);
38     assert(arr[1] == 2);
39     assert(arr[2] == 3);
40     }
41 
42     {
43     const long l1 = 42;
44     std::array arr{1L, 4L, 9L, l1}; // array(T, U...)
45     static_assert(std::is_same_v<decltype(arr)::value_type, long>, "");
46     static_assert(arr.size() == 4, "");
47     assert(arr[0] == 1);
48     assert(arr[1] == 4);
49     assert(arr[2] == 9);
50     assert(arr[3] == l1);
51     }
52 
53 //  Test the implicit deduction guides
54   {
55   std::array<double, 2> source = {4.0, 5.0};
56   std::array arr(source);   // array(array)
57     static_assert(std::is_same_v<decltype(arr), decltype(source)>, "");
58     static_assert(std::is_same_v<decltype(arr), std::array<double, 2>>, "");
59     assert(arr[0] == 4.0);
60     assert(arr[1] == 5.0);
61   }
62 }
63