1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: c++98, c++03, c++11, c++14
14 // any::swap(any &) noexcept
16 // Test swap(large, small) and swap(small, large)
21 #include "any_helpers.h"
26 template <class LHS, class RHS>
28 assert(LHS::count == 0);
29 assert(RHS::count == 0);
33 assert(LHS::count == 1);
34 assert(RHS::count == 1);
38 assert(LHS::count == 1);
39 assert(RHS::count == 1);
41 assertContains<RHS>(a1, 2);
42 assertContains<LHS>(a2, 1);
44 assert(LHS::count == 0);
45 assert(RHS::count == 0);
46 assert(LHS::copied == 0);
47 assert(RHS::copied == 0);
51 void test_swap_empty() {
52 assert(Tp::count == 0);
56 assert(Tp::count == 1);
60 assert(Tp::count == 1);
62 assertContains<Tp>(a2, 1);
65 assert(Tp::count == 0);
69 assert(Tp::count == 1);
73 assert(Tp::count == 1);
75 assertContains<Tp>(a2, 1);
78 assert(Tp::count == 0);
79 assert(Tp::copied == 0);
88 , "any::swap(any&) must be noexcept"
92 void test_self_swap() {
104 assertContains<T>(a, 42);
105 assert(T::count == 1);
106 assert(T::copied == 0);
107 LIBCPP_ASSERT(T::moved == 0);
109 assert(small::count == 0);
115 assertContains<T>(a, 42);
116 assert(T::count == 1);
117 assert(T::copied == 0);
118 LIBCPP_ASSERT(T::moved == 0);
120 assert(large::count == 0);
126 test_swap_empty<small>();
127 test_swap_empty<large>();
128 test_swap<small1, small2>();
129 test_swap<large1, large2>();
130 test_swap<small, large>();
131 test_swap<large, small>();