62 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <array>10// UNSUPPORTED: c++03, c++11, c++1411 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 // Test the explicit deduction guides25 {26 std::array arr{1, 2, 3}; // array(T, U...)27 static_assert(std::is_same_v<decltype(arr), std::array<int, 3>>, "");28 assert(arr[0] == 1);29 assert(arr[1] == 2);30 assert(arr[2] == 3);31 }32 33 {34 const long l1 = 42;35 std::array arr{1L, 4L, 9L, l1}; // array(T, U...)36 static_assert(std::is_same_v<decltype(arr)::value_type, long>, "");37 static_assert(arr.size() == 4, "");38 assert(arr[0] == 1);39 assert(arr[1] == 4);40 assert(arr[2] == 9);41 assert(arr[3] == l1);42 }43 44 // Test the implicit deduction guides45 {46 std::array<double, 2> source = {4.0, 5.0};47 std::array arr(source); // array(array)48 static_assert(std::is_same_v<decltype(arr), decltype(source)>, "");49 static_assert(std::is_same_v<decltype(arr), std::array<double, 2>>, "");50 assert(arr[0] == 4.0);51 assert(arr[1] == 5.0);52 }53 54 return true;55}56 57int main(int, char**) {58 tests();59 static_assert(tests(), "");60 return 0;61}62