//===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include #include #include #include int main() { #if _LIBCPP_STD_VER > 11 typedef std::complex cf; { auto t1 = std::tuple { 42, "Hi", { 1,2 }}; assert ( std::get(t1) == 42 ); // find at the beginning assert ( std::get(t1) == "Hi" ); // find in the middle assert ( std::get(t1).real() == 1 ); // find at the end assert ( std::get(t1).imag() == 2 ); } { auto t2 = std::tuple { 42, "Hi", 23, { 1,2 }}; // get would fail! assert ( std::get(t2) == "Hi" ); assert (( std::get(t2) == cf{ 1,2 } )); } { constexpr std::tuple p5 { 1, 2, 3.4, 5.6 }; static_assert ( std::get(p5) == 1, "" ); static_assert ( std::get(p5) == 2, "" ); } { const std::tuple p5 { 1, 2, 3.4, 5.6 }; const int &i1 = std::get(p5); const int &i2 = std::get(p5); assert ( i1 == 1 ); assert ( i2 == 2 ); } { typedef std::unique_ptr upint; std::tuple t(upint(new int(4))); upint p = std::get(std::move(t)); // get rvalue assert(*p == 4); assert(std::get<0>(t) == nullptr); // has been moved from } #endif }