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