Marshall Clow | 8bf1f08 | 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 | |
| 20 | int main() |
| 21 | { |
| 22 | { |
| 23 | typedef double T; |
| 24 | typedef std::array<T, 3> C; |
| 25 | C c = {1, 2, 3.5}; |
| 26 | C::reference r1 = c[0]; |
| 27 | assert(r1 == 1); |
| 28 | r1 = 5.5; |
| 29 | assert(c.front() == 5.5); |
| 30 | |
| 31 | C::reference r2 = c[2]; |
| 32 | assert(r2 == 3.5); |
| 33 | r2 = 7.5; |
| 34 | assert(c.back() == 7.5); |
| 35 | } |
| 36 | { |
| 37 | typedef double T; |
| 38 | typedef std::array<T, 3> C; |
| 39 | const C c = {1, 2, 3.5}; |
| 40 | C::const_reference r1 = c[0]; |
| 41 | assert(r1 == 1); |
| 42 | C::const_reference r2 = c[2]; |
| 43 | assert(r2 == 3.5); |
| 44 | } |
| 45 | |
| 46 | #if _LIBCPP_STD_VER > 11 |
| 47 | { |
| 48 | typedef double T; |
| 49 | typedef std::array<T, 3> C; |
| 50 | constexpr C c = {1, 2, 3.5}; |
| 51 | |
| 52 | constexpr T t1 = c[0]; |
| 53 | static_assert (t1 == 1, ""); |
| 54 | |
| 55 | constexpr T t2 = c[2]; |
| 56 | static_assert (t2 == 3.5, ""); |
| 57 | } |
| 58 | #endif |
| 59 | |
| 60 | } |