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 front();
13 // reference back();
14 // const_reference front(); // constexpr in C++14
15 // const_reference back(); // constexpr in C++14
16 
17 #include <array>
18 #include <cassert>
19 
20 #include "test_macros.h"
21 
22 // std::array is explicitly allowed to be initialized with A a = { init-list };.
23 // Disable the missing braces warning for this reason.
24 #include "disable_missing_braces_warning.h"
25 
26 int main()
27 {
28     {
29         typedef double T;
30         typedef std::array<T, 3> C;
31         C c = {1, 2, 3.5};
32 
33         C::reference r1 = c.front();
34         assert(r1 == 1);
35         r1 = 5.5;
36         assert(c[0] == 5.5);
37 
38         C::reference r2 = c.back();
39         assert(r2 == 3.5);
40         r2 = 7.5;
41         assert(c[2] == 7.5);
42     }
43     {
44         typedef double T;
45         typedef std::array<T, 3> C;
46         const C c = {1, 2, 3.5};
47         C::const_reference r1 = c.front();
48         assert(r1 == 1);
49 
50         C::const_reference r2 = c.back();
51         assert(r2 == 3.5);
52     }
53 
54 #if TEST_STD_VER > 11
55     {
56         typedef double T;
57         typedef std::array<T, 3> C;
58         constexpr C c = {1, 2, 3.5};
59 
60         constexpr T t1 = c.front();
61         static_assert (t1 == 1, "");
62 
63         constexpr T t2 = c.back();
64         static_assert (t2 == 3.5, "");
65     }
66 #endif
67 
68 }
69