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// <utility>
10
11// template <class T1, class T2> struct pair
12
13// void swap(pair& p);
14
15#include <utility>
16#include <cassert>
17
18#include "test_macros.h"
19
20struct S {
21 int i;
22 TEST_CONSTEXPR_CXX20 S() : i(0) {}
23 TEST_CONSTEXPR_CXX20 S(int j) : i(j) {}
24 TEST_CONSTEXPR_CXX20 bool operator==(int x) const { return i == x; }
25};
26
27TEST_CONSTEXPR_CXX20 bool test() {
28 {
29 typedef std::pair<int, short> P1;
30 P1 p1(3, static_cast<short>(4));
31 P1 p2(5, static_cast<short>(6));
32 p1.swap(p&: p2);
33 assert(p1.first == 5);
34 assert(p1.second == 6);
35 assert(p2.first == 3);
36 assert(p2.second == 4);
37 }
38 {
39 typedef std::pair<int, S> P1;
40 P1 p1(3, S(4));
41 P1 p2(5, S(6));
42 p1.swap(p&: p2);
43 assert(p1.first == 5);
44 assert(p1.second == 6);
45 assert(p2.first == 3);
46 assert(p2.second == 4);
47 }
48 return true;
49}
50
51int main(int, char**) {
52 test();
53#if TEST_STD_VER >= 20
54 static_assert(test());
55#endif
56
57 return 0;
58}
59

source code of libcxx/test/std/utilities/utility/pairs/pairs.pair/swap.pass.cpp