1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // <tuple> 10 11 // template <class... Types> class tuple; 12 13 // void swap(tuple& rhs); 14 15 // UNSUPPORTED: c++03 16 17 #include <tuple> 18 #include <cassert> 19 20 #include "test_macros.h" 21 #include "MoveOnly.h" 22 23 TEST_CONSTEXPR_CXX20 24 bool test() 25 { 26 { 27 typedef std::tuple<> T; 28 T t0; 29 T t1; 30 t0.swap(t1); 31 } 32 { 33 typedef std::tuple<MoveOnly> T; 34 T t0(MoveOnly(0)); 35 T t1(MoveOnly(1)); 36 t0.swap(t1); 37 assert(std::get<0>(t0) == 1); 38 assert(std::get<0>(t1) == 0); 39 } 40 { 41 typedef std::tuple<MoveOnly, MoveOnly> T; 42 T t0(MoveOnly(0), MoveOnly(1)); 43 T t1(MoveOnly(2), MoveOnly(3)); 44 t0.swap(t1); 45 assert(std::get<0>(t0) == 2); 46 assert(std::get<1>(t0) == 3); 47 assert(std::get<0>(t1) == 0); 48 assert(std::get<1>(t1) == 1); 49 } 50 { 51 typedef std::tuple<MoveOnly, MoveOnly, MoveOnly> T; 52 T t0(MoveOnly(0), MoveOnly(1), MoveOnly(2)); 53 T t1(MoveOnly(3), MoveOnly(4), MoveOnly(5)); 54 t0.swap(t1); 55 assert(std::get<0>(t0) == 3); 56 assert(std::get<1>(t0) == 4); 57 assert(std::get<2>(t0) == 5); 58 assert(std::get<0>(t1) == 0); 59 assert(std::get<1>(t1) == 1); 60 assert(std::get<2>(t1) == 2); 61 } 62 return true; 63 } 64 65 int main(int, char**) 66 { 67 test(); 68 #if TEST_STD_VER > 17 69 static_assert(test()); 70 #endif 71 72 return 0; 73 } 74