Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / utilities / utility / pairs / pairs.pair / swap.pass.cpp
bloba2d720ff42ea653fd2cf7e4bfd4ca0edaf14d1a5
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 //===----------------------------------------------------------------------===//
9 // <utility>
11 // template <class T1, class T2> struct pair
13 // void swap(pair& p);
15 #include <utility>
16 #include <cassert>
18 #include "test_macros.h"
20 struct 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; }
27 TEST_CONSTEXPR_CXX20 bool test() {
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(p2);
33 assert(p1.first == 5);
34 assert(p1.second == 6);
35 assert(p2.first == 3);
36 assert(p2.second == 4);
39 typedef std::pair<int, S> P1;
40 P1 p1(3, S(4));
41 P1 p2(5, S(6));
42 p1.swap(p2);
43 assert(p1.first == 5);
44 assert(p1.second == 6);
45 assert(p2.first == 3);
46 assert(p2.second == 4);
48 return true;
51 int main(int, char**) {
52 test();
53 #if TEST_STD_VER >= 20
54 static_assert(test());
55 #endif
57 return 0;