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 #include <tuple> 11 #include <string> 12 #include <complex> 13 14 #include <cassert> 15 16 int main() 17 { 18 #if _LIBCPP_STD_VER > 11 19 typedef std::complex<float> cf; 20 { 21 auto t1 = std::tuple<int, std::string, cf> { 42, "Hi", { 1,2 }}; 22 assert ( std::get<int>(t1) == 42 ); // find at the beginning 23 assert ( std::get<std::string>(t1) == "Hi" ); // find in the middle 24 assert ( std::get<cf>(t1).real() == 1 ); // find at the end 25 assert ( std::get<cf>(t1).imag() == 2 ); 26 } 27 28 { 29 auto t2 = std::tuple<int, std::string, int, cf> { 42, "Hi", 23, { 1,2 }}; 30 // get<int> would fail! 31 assert ( std::get<std::string>(t2) == "Hi" ); 32 assert (( std::get<cf>(t2) == cf{ 1,2 } )); 33 } 34 35 { 36 constexpr std::tuple<int, const int, double, double> p5 { 1, 2, 3.4, 5.6 }; 37 static_assert ( std::get<int>(p5) == 1, "" ); 38 static_assert ( std::get<const int>(p5) == 2, "" ); 39 } 40 41 { 42 const std::tuple<int, const int, double, double> p5 { 1, 2, 3.4, 5.6 }; 43 const int &i1 = std::get<int>(p5); 44 const int &i2 = std::get<const int>(p5); 45 assert ( i1 == 1 ); 46 assert ( i2 == 2 ); 47 } 48 49 { 50 typedef std::unique_ptr<int> upint; 51 std::tuple<upint> t(upint(new int(4))); 52 upint p = std::get<upint>(std::move(t)); // get rvalue 53 assert(*p == 4); 54 assert(std::get<0>(t) == nullptr); // has been moved from 55 } 56 57 #endif 58 } 59