blob: c550d141bcbf4b83b289aa76b6680b10c09f5b5f [file] [log] [blame]
Marshall Clow8fc4f5a2013-07-17 18:25:36 +00001//===----------------------------------------------------------------------===//
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 Fiselier02bb4bd2015-07-18 23:56:04 +000020#include "test_macros.h"
21
Dan Albert1d4a1ed2016-05-25 22:36:09 -070022#include "suppress_array_warnings.h"
Eric Fiselier02bb4bd2015-07-18 23:56:04 +000023
Marshall Clow8fc4f5a2013-07-17 18:25:36 +000024int 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 Fiselier02bb4bd2015-07-18 23:56:04 +000049
50#if TEST_STD_VER > 11
Marshall Clow8fc4f5a2013-07-17 18:25:36 +000051 {
52 typedef double T;
53 typedef std::array<T, 3> C;
54 constexpr C c = {1, 2, 3.5};
Eric Fiselier02bb4bd2015-07-18 23:56:04 +000055
Marshall Clow8fc4f5a2013-07-17 18:25:36 +000056 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}