Home | History | Annotate | Download | only in array
      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 #include "test_macros.h"
     21 
     22 #include "suppress_array_warnings.h"
     23 
     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     }
     49 
     50 #if TEST_STD_VER > 11
     51     {
     52         typedef double T;
     53         typedef std::array<T, 3> C;
     54         constexpr C c = {1, 2, 3.5};
     55 
     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 }
     65