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 #include "test_macros.h"
26 
27 int main()
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