Home | History | Annotate | Download | only in tuple.elem
      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 // <tuple>
     11 
     12 // template <class... Types> class tuple;
     13 
     14 // template <size_t I, class... Types>
     15 //   typename tuple_element<I, tuple<Types...> >::type const&
     16 //   get(const tuple<Types...>& t);
     17 
     18 // UNSUPPORTED: c++98, c++03
     19 
     20 #include <tuple>
     21 #include <string>
     22 #include <cassert>
     23 
     24 #include "test_macros.h"
     25 
     26 struct Empty {};
     27 
     28 int main()
     29 {
     30     {
     31         typedef std::tuple<int> T;
     32         const T t(3);
     33         assert(std::get<0>(t) == 3);
     34     }
     35     {
     36         typedef std::tuple<std::string, int> T;
     37         const T t("high", 5);
     38         assert(std::get<0>(t) == "high");
     39         assert(std::get<1>(t) == 5);
     40     }
     41 #if TEST_STD_VER > 11
     42     {
     43         typedef std::tuple<double, int> T;
     44         constexpr T t(2.718, 5);
     45         static_assert(std::get<0>(t) == 2.718, "");
     46         static_assert(std::get<1>(t) == 5, "");
     47     }
     48     {
     49         typedef std::tuple<Empty> T;
     50         constexpr T t{Empty()};
     51         constexpr Empty e = std::get<0>(t);
     52         ((void)e); // Prevent unused warning
     53     }
     54 #endif
     55     {
     56         typedef std::tuple<double&, std::string, int> T;
     57         double d = 1.5;
     58         const T t(d, "high", 5);
     59         assert(std::get<0>(t) == 1.5);
     60         assert(std::get<1>(t) == "high");
     61         assert(std::get<2>(t) == 5);
     62         std::get<0>(t) = 2.5;
     63         assert(std::get<0>(t) == 2.5);
     64         assert(std::get<1>(t) == "high");
     65         assert(std::get<2>(t) == 5);
     66         assert(d == 2.5);
     67     }
     68 }
     69