Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 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 | // <array> |
| 11 | |
| 12 | // reference operator[] (size_type) |
| 13 | // const_reference operator[] (size_type); // constexpr in C++14 |
| 14 | // reference at (size_type) |
| 15 | // const_reference at (size_type); // constexpr in C++14 |
| 16 | |
| 17 | #include <array> |
| 18 | #include <cassert> |
| 19 | |
Eric Fiselier | 02bb4bd | 2015-07-18 23:56:04 +0000 | [diff] [blame] | 20 | #include "test_macros.h" |
| 21 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 22 | #include "suppress_array_warnings.h" |
Eric Fiselier | 02bb4bd | 2015-07-18 23:56:04 +0000 | [diff] [blame] | 23 | |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 24 | int main() |
| 25 | { |
| 26 | { |
| 27 | typedef double T; |
| 28 | typedef std::array<T, 3> C; |
| 29 | C c = {1, 2, 3.5}; |
| 30 | C::reference r1 = c[0]; |
| 31 | assert(r1 == 1); |
| 32 | r1 = 5.5; |
| 33 | assert(c.front() == 5.5); |
| 34 | |
| 35 | C::reference r2 = c[2]; |
| 36 | assert(r2 == 3.5); |
| 37 | r2 = 7.5; |
| 38 | assert(c.back() == 7.5); |
| 39 | } |
| 40 | { |
| 41 | typedef double T; |
| 42 | typedef std::array<T, 3> C; |
| 43 | const C c = {1, 2, 3.5}; |
| 44 | C::const_reference r1 = c[0]; |
| 45 | assert(r1 == 1); |
| 46 | C::const_reference r2 = c[2]; |
| 47 | assert(r2 == 3.5); |
| 48 | } |
Eric Fiselier | 02bb4bd | 2015-07-18 23:56:04 +0000 | [diff] [blame] | 49 | |
| 50 | #if TEST_STD_VER > 11 |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 51 | { |
| 52 | typedef double T; |
| 53 | typedef std::array<T, 3> C; |
| 54 | constexpr C c = {1, 2, 3.5}; |
Eric Fiselier | 02bb4bd | 2015-07-18 23:56:04 +0000 | [diff] [blame] | 55 | |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 56 | constexpr T t1 = c[0]; |
| 57 | static_assert (t1 == 1, ""); |
| 58 | |
| 59 | constexpr T t2 = c[2]; |
| 60 | static_assert (t2 == 3.5, ""); |
| 61 | } |
| 62 | #endif |
| 63 | |
| 64 | } |