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 return {args...};
21}
22
23TEST_CONSTEXPR_CXX14 bool tests() {
24 {
25 std::array<double, 1> array = {3.3};
26 assert(std::get<0>(array) == 3.3);
27 std::get<0>(arr&: array) = 99.1;
28 assert(std::get<0>(array) == 99.1);
29 }
30 {
31 std::array<double, 2> array = {3.3, 4.4};
32 assert(std::get<0>(array) == 3.3);
33 assert(std::get<1>(array) == 4.4);
34 std::get<0>(arr&: array) = 99.1;
35 std::get<1>(arr&: array) = 99.2;
36 assert(std::get<0>(array) == 99.1);
37 assert(std::get<1>(array) == 99.2);
38 }
39 {
40 std::array<double, 3> array = {3.3, 4.4, 5.5};
41 assert(std::get<0>(array) == 3.3);
42 assert(std::get<1>(array) == 4.4);
43 assert(std::get<2>(array) == 5.5);
44 std::get<1>(arr&: array) = 99.2;
45 assert(std::get<0>(array) == 3.3);
46 assert(std::get<1>(array) == 99.2);
47 assert(std::get<2>(array) == 5.5);
48 }
49 {
50 std::array<double, 1> array = {3.3};
51 static_assert(std::is_same<double&, decltype(std::get<0>(arr&: array))>::value, "");
52 }
53 {
54 assert(std::get<0>(tempArray(1, 2, 3)) == 1);
55 assert(std::get<1>(tempArray(1, 2, 3)) == 2);
56 assert(std::get<2>(tempArray(1, 2, 3)) == 3);
57 }
58
59 return true;
60}
61
62int main(int, char**) {
63 tests();
64#if TEST_STD_VER >= 14
65 static_assert(tests(), "");
66#endif
67 return 0;
68}
69

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