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 #if __cplusplus > 201103L
     18 struct S {
     19    std::array<int, 3> a;
     20    int k;
     21    constexpr S() : a{1,2,3}, k(std::get<2>(a)) {}
     22    };
     23 
     24 constexpr std::array<int, 2> getArr () { return { 3, 4 }; }
     25 #endif
     26 
     27 int main()
     28 {
     29     {
     30         typedef double T;
     31         typedef std::array<T, 3> C;
     32         C c = {1, 2, 3.5};
     33         std::get<1>(c) = 5.5;
     34         assert(c[0] == 1);
     35         assert(c[1] == 5.5);
     36         assert(c[2] == 3.5);
     37     }
     38 #if _LIBCPP_STD_VER > 11
     39     {
     40         typedef double T;
     41         typedef std::array<T, 3> C;
     42         constexpr C c = {1, 2, 3.5};
     43         static_assert(std::get<0>(c) == 1, "");
     44         static_assert(std::get<1>(c) == 2, "");
     45         static_assert(std::get<2>(c) == 3.5, "");
     46     }
     47     {
     48         static_assert(S().k == 3, "");
     49         static_assert(std::get<1>(getArr()) == 4, "");
     50     }
     51 #endif
     52 }
     53