]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/experimental/any/any.class/any.modifiers/swap.pass.cpp
Vendor import of libc++ trunk r302418:
[FreeBSD/FreeBSD.git] / test / std / experimental / any / any.class / any.modifiers / swap.pass.cpp
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // UNSUPPORTED: c++98, c++03, c++11
11
12 // XFAIL: with_system_cxx_lib=macosx10.12
13 // XFAIL: with_system_cxx_lib=macosx10.11
14 // XFAIL: with_system_cxx_lib=macosx10.10
15 // XFAIL: with_system_cxx_lib=macosx10.9
16 // XFAIL: with_system_cxx_lib=macosx10.7
17 // XFAIL: with_system_cxx_lib=macosx10.8
18
19 // <experimental/any>
20
21 // any::swap(any &) noexcept
22
23 // Test swap(large, small) and swap(small, large)
24
25 #include <experimental/any>
26 #include <cassert>
27
28 #include "experimental_any_helpers.h"
29
30 using std::experimental::any;
31 using std::experimental::any_cast;
32
33 template <class LHS, class RHS>
34 void test_swap() {
35     assert(LHS::count == 0);
36     assert(RHS::count == 0);
37     {
38         any a1((LHS(1)));
39         any a2(RHS{2});
40         assert(LHS::count == 1);
41         assert(RHS::count == 1);
42
43         a1.swap(a2);
44
45         assert(LHS::count == 1);
46         assert(RHS::count == 1);
47
48         assertContains<RHS>(a1, 2);
49         assertContains<LHS>(a2, 1);
50     }
51     assert(LHS::count == 0);
52     assert(RHS::count == 0);
53     assert(LHS::copied == 0);
54     assert(RHS::copied == 0);
55 }
56
57 template <class Tp>
58 void test_swap_empty() {
59     assert(Tp::count == 0);
60     {
61         any a1((Tp(1)));
62         any a2;
63         assert(Tp::count == 1);
64
65         a1.swap(a2);
66
67         assert(Tp::count == 1);
68
69         assertContains<Tp>(a2, 1);
70         assertEmpty(a1);
71     }
72     assert(Tp::count == 0);
73     {
74         any a1((Tp(1)));
75         any a2;
76         assert(Tp::count == 1);
77
78         a2.swap(a1);
79
80         assert(Tp::count == 1);
81
82         assertContains<Tp>(a2, 1);
83         assertEmpty(a1);
84     }
85     assert(Tp::count == 0);
86     assert(Tp::copied == 0);
87 }
88
89 void test_noexcept()
90 {
91     any a1;
92     any a2;
93     static_assert(
94         noexcept(a1.swap(a2))
95       , "any::swap(any&) must be noexcept"
96       );
97 }
98
99 int main()
100 {
101     test_noexcept();
102     test_swap_empty<small>();
103     test_swap_empty<large>();
104     test_swap<small1, small2>();
105     test_swap<large1, large2>();
106     test_swap<small, large>();
107     test_swap<large, small>();
108 }