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 struct Empty {};
     25 
     26 int main()
     27 {
     28     {
     29         typedef std::tuple<int> T;
     30         const T t(3);
     31         assert(std::get<0>(t) == 3);
     32     }
     33     {
     34         typedef std::tuple<std::string, int> T;
     35         const T t("high", 5);
     36         assert(std::get<0>(t) == "high");
     37         assert(std::get<1>(t) == 5);
     38     }
     39 #if _LIBCPP_STD_VER > 11
     40     {
     41         typedef std::tuple<double, int> T;
     42         constexpr T t(2.718, 5);
     43         static_assert(std::get<0>(t) == 2.718, "");
     44         static_assert(std::get<1>(t) == 5, "");
     45     }
     46     {
     47         typedef std::tuple<Empty> T;
     48         constexpr T t{Empty()};
     49         constexpr Empty e = std::get<0>(t);
     50         ((void)e); // Prevent unused warning
     51     }
     52 #endif
     53     {
     54         typedef std::tuple<double&, std::string, int> T;
     55         double d = 1.5;
     56         const T t(d, "high", 5);
     57         assert(std::get<0>(t) == 1.5);
     58         assert(std::get<1>(t) == "high");
     59         assert(std::get<2>(t) == 5);
     60         std::get<0>(t) = 2.5;
     61         assert(std::get<0>(t) == 2.5);
     62         assert(std::get<1>(t) == "high");
     63         assert(std::get<2>(t) == 5);
     64         assert(d == 2.5);
     65     }
     66 }
     67