Home | History | Annotate | Download | only in array.tuple
      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 // template <size_t I, class T, size_t N> T& get(array<T, N>& a);
     13 
     14 #include <array>
     15 #include <cassert>
     16 
     17 #include "test_macros.h"
     18 
     19 // std::array is explicitly allowed to be initialized with A a = { init-list };.
     20 // Disable the missing braces warning for this reason.
     21 #include "disable_missing_braces_warning.h"
     22 
     23 
     24 #if TEST_STD_VER > 11
     25 struct S {
     26    std::array<int, 3> a;
     27    int k;
     28    constexpr S() : a{1,2,3}, k(std::get<2>(a)) {}
     29 };
     30 
     31 constexpr std::array<int, 2> getArr () { return { 3, 4 }; }
     32 #endif
     33 
     34 int main()
     35 {
     36     {
     37         typedef double T;
     38         typedef std::array<T, 3> C;
     39         C c = {1, 2, 3.5};
     40         std::get<1>(c) = 5.5;
     41         assert(c[0] == 1);
     42         assert(c[1] == 5.5);
     43         assert(c[2] == 3.5);
     44     }
     45 #if TEST_STD_VER > 11
     46     {
     47         typedef double T;
     48         typedef std::array<T, 3> C;
     49         constexpr C c = {1, 2, 3.5};
     50         static_assert(std::get<0>(c) == 1, "");
     51         static_assert(std::get<1>(c) == 2, "");
     52         static_assert(std::get<2>(c) == 3.5, "");
     53     }
     54     {
     55         static_assert(S().k == 3, "");
     56         static_assert(std::get<1>(getArr()) == 4, "");
     57     }
     58 #endif
     59 }
     60