10ca8c089SMarshall Clow //===----------------------------------------------------------------------===//
20ca8c089SMarshall Clow //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60ca8c089SMarshall Clow //
70ca8c089SMarshall Clow //===----------------------------------------------------------------------===//
80ca8c089SMarshall Clow
90ca8c089SMarshall Clow // <array>
10*31cbe0f2SLouis Dionne // UNSUPPORTED: c++03, c++11, c++14
110ca8c089SMarshall Clow
120ca8c089SMarshall Clow // template <class T, class... U>
130ca8c089SMarshall Clow // array(T, U...) -> array<T, 1 + sizeof...(U)>;
140ca8c089SMarshall Clow //
150ca8c089SMarshall Clow // Requires: (is_same_v<T, U> && ...) is true. Otherwise the program is ill-formed.
160ca8c089SMarshall Clow
170ca8c089SMarshall Clow #include <array>
180ca8c089SMarshall Clow #include <cassert>
190ca8c089SMarshall Clow #include <cstddef>
200ca8c089SMarshall Clow
210ca8c089SMarshall Clow #include "test_macros.h"
220ca8c089SMarshall Clow
tests()2377b9abfcSLouis Dionne constexpr bool tests()
240ca8c089SMarshall Clow {
250ca8c089SMarshall Clow // Test the explicit deduction guides
260ca8c089SMarshall Clow {
270ca8c089SMarshall Clow std::array arr{1,2,3}; // array(T, U...)
280ca8c089SMarshall Clow static_assert(std::is_same_v<decltype(arr), std::array<int, 3>>, "");
290ca8c089SMarshall Clow assert(arr[0] == 1);
300ca8c089SMarshall Clow assert(arr[1] == 2);
310ca8c089SMarshall Clow assert(arr[2] == 3);
320ca8c089SMarshall Clow }
330ca8c089SMarshall Clow
340ca8c089SMarshall Clow {
350ca8c089SMarshall Clow const long l1 = 42;
360ca8c089SMarshall Clow std::array arr{1L, 4L, 9L, l1}; // array(T, U...)
370ca8c089SMarshall Clow static_assert(std::is_same_v<decltype(arr)::value_type, long>, "");
380ca8c089SMarshall Clow static_assert(arr.size() == 4, "");
390ca8c089SMarshall Clow assert(arr[0] == 1);
400ca8c089SMarshall Clow assert(arr[1] == 4);
410ca8c089SMarshall Clow assert(arr[2] == 9);
420ca8c089SMarshall Clow assert(arr[3] == l1);
430ca8c089SMarshall Clow }
440ca8c089SMarshall Clow
450ca8c089SMarshall Clow // Test the implicit deduction guides
460ca8c089SMarshall Clow {
470ca8c089SMarshall Clow std::array<double, 2> source = {4.0, 5.0};
480ca8c089SMarshall Clow std::array arr(source); // array(array)
490ca8c089SMarshall Clow static_assert(std::is_same_v<decltype(arr), decltype(source)>, "");
500ca8c089SMarshall Clow static_assert(std::is_same_v<decltype(arr), std::array<double, 2>>, "");
510ca8c089SMarshall Clow assert(arr[0] == 4.0);
520ca8c089SMarshall Clow assert(arr[1] == 5.0);
530ca8c089SMarshall Clow }
542df59c50SJF Bastien
5577b9abfcSLouis Dionne return true;
5677b9abfcSLouis Dionne }
5777b9abfcSLouis Dionne
main(int,char **)5877b9abfcSLouis Dionne int main(int, char**)
5977b9abfcSLouis Dionne {
6077b9abfcSLouis Dionne tests();
6177b9abfcSLouis Dionne static_assert(tests(), "");
622df59c50SJF Bastien return 0;
630ca8c089SMarshall Clow }
64