1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // XFAIL: libcpp-no-exceptions 11 // <array> 12 13 // reference operator[] (size_type) 14 // const_reference operator[] (size_type); // constexpr in C++14 15 // reference at (size_type) 16 // const_reference at (size_type); // constexpr in C++14 17 18 #include <array> 19 #include <cassert> 20 21 #include "test_macros.h" 22 23 // std::array is explicitly allowed to be initialized with A a = { init-list };. 24 // Disable the missing braces warning for this reason. 25 #include "disable_missing_braces_warning.h" 26 27 int main() 28 { 29 { 30 typedef double T; 31 typedef std::array<T, 3> C; 32 C c = {1, 2, 3.5}; 33 C::reference r1 = c.at(0); 34 assert(r1 == 1); 35 r1 = 5.5; 36 assert(c.front() == 5.5); 37 38 C::reference r2 = c.at(2); 39 assert(r2 == 3.5); 40 r2 = 7.5; 41 assert(c.back() == 7.5); 42 43 try { (void) c.at(3); } 44 catch (const std::out_of_range &) {} 45 } 46 { 47 typedef double T; 48 typedef std::array<T, 3> C; 49 const C c = {1, 2, 3.5}; 50 C::const_reference r1 = c.at(0); 51 assert(r1 == 1); 52 53 C::const_reference r2 = c.at(2); 54 assert(r2 == 3.5); 55 56 try { (void) c.at(3); } 57 catch (const std::out_of_range &) {} 58 } 59 60 #if TEST_STD_VER > 11 61 { 62 typedef double T; 63 typedef std::array<T, 3> C; 64 constexpr C c = {1, 2, 3.5}; 65 66 constexpr T t1 = c.at(0); 67 static_assert (t1 == 1, ""); 68 69 constexpr T t2 = c.at(2); 70 static_assert (t2 == 3.5, ""); 71 } 72 #endif 73 74 } 75