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 
18 // std::array is explicitly allowed to be initialized with A a = { init-list };.
19 // Disable the missing braces warning for this reason.
20 #include "disable_missing_braces_warning.h"
21 
22 
23 #if TEST_STD_VER > 11
24 struct S {
25    std::array<int, 3> a;
26    int k;
27    constexpr S() : a{1,2,3}, k(std::get<2>(a)) {}
28 };
29 
30 constexpr std::array<int, 2> getArr () { return { 3, 4 }; }
31 #endif
32 
33 int main(int, char**)
34 {
35     {
36         typedef double T;
37         typedef std::array<T, 3> C;
38         C c = {1, 2, 3.5};
39         std::get<1>(c) = 5.5;
40         assert(c[0] == 1);
41         assert(c[1] == 5.5);
42         assert(c[2] == 3.5);
43     }
44 #if TEST_STD_VER > 11
45     {
46         typedef double T;
47         typedef std::array<T, 3> C;
48         constexpr C c = {1, 2, 3.5};
49         static_assert(std::get<0>(c) == 1, "");
50         static_assert(std::get<1>(c) == 2, "");
51         static_assert(std::get<2>(c) == 3.5, "");
52     }
53     {
54         static_assert(S().k == 3, "");
55         static_assert(std::get<1>(getArr()) == 4, "");
56     }
57 #endif
58 
59   return 0;
60 }
61