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
11// template <size_t I, class T, size_t N> T& get(array<T, N>& a);
12
13#include <array>
14#include <cassert>
15
16#include "test_macros.h"
17
18template <typename ...T>
19TEST_CONSTEXPR std::array<int, sizeof...(T)> tempArray(T ...args)
20{
21 return {args...};
22}
23
24TEST_CONSTEXPR_CXX14 bool tests()
25{
26 {
27 std::array<double, 1> array = {3.3};
28 assert(std::get<0>(array) == 3.3);
29 std::get<0>(arr&: array) = 99.1;
30 assert(std::get<0>(array) == 99.1);
31 }
32 {
33 std::array<double, 2> array = {3.3, 4.4};
34 assert(std::get<0>(array) == 3.3);
35 assert(std::get<1>(array) == 4.4);
36 std::get<0>(arr&: array) = 99.1;
37 std::get<1>(arr&: array) = 99.2;
38 assert(std::get<0>(array) == 99.1);
39 assert(std::get<1>(array) == 99.2);
40 }
41 {
42 std::array<double, 3> array = {3.3, 4.4, 5.5};
43 assert(std::get<0>(array) == 3.3);
44 assert(std::get<1>(array) == 4.4);
45 assert(std::get<2>(array) == 5.5);
46 std::get<1>(arr&: array) = 99.2;
47 assert(std::get<0>(array) == 3.3);
48 assert(std::get<1>(array) == 99.2);
49 assert(std::get<2>(array) == 5.5);
50 }
51 {
52 std::array<double, 1> array = {3.3};
53 static_assert(std::is_same<double&, decltype(std::get<0>(arr&: array))>::value, "");
54 }
55 {
56 assert(std::get<0>(tempArray(1, 2, 3)) == 1);
57 assert(std::get<1>(tempArray(1, 2, 3)) == 2);
58 assert(std::get<2>(tempArray(1, 2, 3)) == 3);
59 }
60
61 return true;
62}
63
64int main(int, char**)
65{
66 tests();
67#if TEST_STD_VER >= 14
68 static_assert(tests(), "");
69#endif
70 return 0;
71}
72

source code of libcxx/test/std/containers/sequences/array/array.tuple/get.pass.cpp