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#include "test_macros.h"
22
23constexpr bool tests()
24{
25 // Test the explicit deduction guides
26 {
27 std::array arr{1,2,3}; // array(T, U...)
28 static_assert(std::is_same_v<decltype(arr), std::array<int, 3>>, "");
29 assert(arr[0] == 1);
30 assert(arr[1] == 2);
31 assert(arr[2] == 3);
32 }
33
34 {
35 const long l1 = 42;
36 std::array arr{1L, 4L, 9L, l1}; // array(T, U...)
37 static_assert(std::is_same_v<decltype(arr)::value_type, long>, "");
38 static_assert(arr.size() == 4, "");
39 assert(arr[0] == 1);
40 assert(arr[1] == 4);
41 assert(arr[2] == 9);
42 assert(arr[3] == l1);
43 }
44
45 // Test the implicit deduction guides
46 {
47 std::array<double, 2> source = {4.0, 5.0};
48 std::array arr(source); // array(array)
49 static_assert(std::is_same_v<decltype(arr), decltype(source)>, "");
50 static_assert(std::is_same_v<decltype(arr), std::array<double, 2>>, "");
51 assert(arr[0] == 4.0);
52 assert(arr[1] == 5.0);
53 }
54
55 return true;
56}
57
58int main(int, char**)
59{
60 tests();
61 static_assert(tests(), "");
62 return 0;
63}
64

source code of libcxx/test/std/containers/sequences/array/array.cons/deduct.pass.cpp