]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/tuple/swap.cc
1 // { dg-do run { target c++11 } }
3 // Copyright (C) 2007-2024 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
21 // NOTE: This makes use of the fact that we know how moveable
22 // is implemented on tuple. If the implementation changed
23 // this test may begin to fail.
27 #include <testsuite_hooks.h>
31 explicit MoveOnly (int j
) : i(j
) { }
33 MoveOnly (MoveOnly
&& m
) : i(m
.i
) { }
35 MoveOnly
& operator=(MoveOnly
&& m
)
36 { i
= m
.i
; return *this; }
38 MoveOnly(MoveOnly
const&) = delete;
39 MoveOnly
& operator=(MoveOnly
const&) = delete;
41 bool operator==(MoveOnly
const& m
) const
44 void swap(MoveOnly
& m
)
45 { std::swap(m
.i
, i
); }
50 void swap(MoveOnly
& m1
, MoveOnly
& m2
)
54 make_move_only (int i
)
55 { return MoveOnly(i
); }
67 std::tuple
<int> t1(1), t2(2);
70 VERIFY( std::get
<0>(t1
) == 2 && std::get
<0>(t2
) == 1 );
75 std::tuple
<int, float> t1(1, 1.0f
), t2(2, 2.0f
);
78 VERIFY( std::get
<0>(t1
) == 2 && std::get
<0>(t2
) == 1 );
79 VERIFY( std::get
<1>(t1
) == 2.0f
&& std::get
<1>(t2
) == 1.0f
);
84 std::tuple
<int, float, MoveOnly
>
85 t1(1, 1.0f
, make_move_only(1)),
86 t2(2, 2.0f
, make_move_only(2));
90 VERIFY( std::get
<0>(t1
) == 2 && std::get
<0>(t2
) == 1 );
91 VERIFY( std::get
<1>(t1
) == 2.0f
&& std::get
<1>(t2
) == 1.0f
);
92 VERIFY( std::get
<2>(t1
) == make_move_only(2)
93 && std::get
<2>(t2
) == make_move_only(1) );