• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
main(int,char **)23 int main(int, char**)
24 {
25     {
26         typedef std::tuple<> T;
27         T t0;
28         T t1;
29         t0.swap(t1);
30     }
31     {
32         typedef std::tuple<MoveOnly> T;
33         T t0(MoveOnly(0));
34         T t1(MoveOnly(1));
35         t0.swap(t1);
36         assert(std::get<0>(t0) == 1);
37         assert(std::get<0>(t1) == 0);
38     }
39     {
40         typedef std::tuple<MoveOnly, MoveOnly> T;
41         T t0(MoveOnly(0), MoveOnly(1));
42         T t1(MoveOnly(2), MoveOnly(3));
43         t0.swap(t1);
44         assert(std::get<0>(t0) == 2);
45         assert(std::get<1>(t0) == 3);
46         assert(std::get<0>(t1) == 0);
47         assert(std::get<1>(t1) == 1);
48     }
49     {
50         typedef std::tuple<MoveOnly, MoveOnly, MoveOnly> T;
51         T t0(MoveOnly(0), MoveOnly(1), MoveOnly(2));
52         T t1(MoveOnly(3), MoveOnly(4), MoveOnly(5));
53         t0.swap(t1);
54         assert(std::get<0>(t0) == 3);
55         assert(std::get<1>(t0) == 4);
56         assert(std::get<2>(t0) == 5);
57         assert(std::get<0>(t1) == 0);
58         assert(std::get<1>(t1) == 1);
59         assert(std::get<2>(t1) == 2);
60     }
61 
62   return 0;
63 }
64