| 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 | // template <class... Types> |
| 14 | // void swap(tuple<Types...>& x, tuple<Types...>& y); |
| 15 | |
| 16 | // UNSUPPORTED: c++03 |
| 17 | |
| 18 | #include <tuple> |
| 19 | #include <cassert> |
| 20 | |
| 21 | #include "test_macros.h" |
| 22 | #include "MoveOnly.h" |
| 23 | |
| 24 | int main(int, char**) |
| 25 | { |
| 26 | { |
| 27 | typedef std::tuple<> T; |
| 28 | T t0; |
| 29 | T t1; |
| 30 | swap(x&: t0, y&: t1); |
| 31 | } |
| 32 | { |
| 33 | typedef std::tuple<MoveOnly> T; |
| 34 | T t0(MoveOnly(0)); |
| 35 | T t1(MoveOnly(1)); |
| 36 | swap(a&: t0, b&: 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 | swap(a&: t0, b&: 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 | swap(a&: t0, b&: 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 | |
| 63 | return 0; |
| 64 | } |
| 65 | |