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: clang-5, apple-clang-9
13 // UNSUPPORTED: libcpp-no-deduction-guides
14 // Clang 5 will generate bad implicit deduction guides
15 // Specifically, for the copy constructor.
16
17
18 // template <class T, class... U>
19 // array(T, U...) -> array<T, 1 + sizeof...(U)>;
20 //
21 // Requires: (is_same_v<T, U> && ...) is true. Otherwise the program is ill-formed.
22
23
24 #include <array>
25 #include <cassert>
26 #include <cstddef>
27
28 // std::array is explicitly allowed to be initialized with A a = { init-list };.
29 // Disable the missing braces warning for this reason.
30 #include "disable_missing_braces_warning.h"
31
32 #include "test_macros.h"
33
main()34 int main()
35 {
36 // Test the explicit deduction guides
37 {
38 std::array arr{1,2,3}; // array(T, U...)
39 static_assert(std::is_same_v<decltype(arr), std::array<int, 3>>, "");
40 assert(arr[0] == 1);
41 assert(arr[1] == 2);
42 assert(arr[2] == 3);
43 }
44
45 {
46 const long l1 = 42;
47 std::array arr{1L, 4L, 9L, l1}; // array(T, U...)
48 static_assert(std::is_same_v<decltype(arr)::value_type, long>, "");
49 static_assert(arr.size() == 4, "");
50 assert(arr[0] == 1);
51 assert(arr[1] == 4);
52 assert(arr[2] == 9);
53 assert(arr[3] == l1);
54 }
55
56 // Test the implicit deduction guides
57 {
58 std::array<double, 2> source = {4.0, 5.0};
59 std::array arr(source); // array(array)
60 static_assert(std::is_same_v<decltype(arr), decltype(source)>, "");
61 static_assert(std::is_same_v<decltype(arr), std::array<double, 2>>, "");
62 assert(arr[0] == 4.0);
63 assert(arr[1] == 5.0);
64 }
65 }
66