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