Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / utilities / any / any.class / any.assign / move.pass.cpp
blob2cfc3f63aa769f04d158966d8df75823934e2f3b
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 // UNSUPPORTED: c++03, c++11, c++14
11 // <any>
13 // any& operator=(any &&);
15 // Test move assignment.
17 #include <any>
18 #include <cassert>
20 #include "any_helpers.h"
21 #include "test_macros.h"
23 template <class LHS, class RHS>
24 void test_move_assign() {
25 assert(LHS::count == 0);
26 assert(RHS::count == 0);
28 LHS const s1(1);
29 std::any a = s1;
30 RHS const s2(2);
31 std::any a2 = s2;
33 assert(LHS::count == 2);
34 assert(RHS::count == 2);
36 a = std::move(a2);
38 assert(LHS::count == 1);
39 assert(RHS::count == 2 + a2.has_value());
40 LIBCPP_ASSERT(RHS::count == 2); // libc++ leaves the object empty
42 assertContains<RHS>(a, 2);
43 if (a2.has_value())
44 assertContains<RHS>(a2, 0);
45 LIBCPP_ASSERT(!a2.has_value());
47 assert(LHS::count == 0);
48 assert(RHS::count == 0);
51 template <class LHS>
52 void test_move_assign_empty() {
53 assert(LHS::count == 0);
55 std::any a;
56 std::any a2 = LHS(1);
58 assert(LHS::count == 1);
60 a = std::move(a2);
62 assert(LHS::count == 1 + a2.has_value());
63 LIBCPP_ASSERT(LHS::count == 1);
65 assertContains<LHS>(a, 1);
66 if (a2.has_value())
67 assertContains<LHS>(a2, 0);
68 LIBCPP_ASSERT(!a2.has_value());
70 assert(LHS::count == 0);
72 std::any a = LHS(1);
73 std::any a2;
75 assert(LHS::count == 1);
77 a = std::move(a2);
79 assert(LHS::count == 0);
81 assertEmpty<LHS>(a);
82 assertEmpty(a2);
84 assert(LHS::count == 0);
87 void test_move_assign_noexcept() {
88 std::any a1;
89 std::any a2;
90 ASSERT_NOEXCEPT(a1 = std::move(a2));
93 int main(int, char**) {
94 test_move_assign_noexcept();
95 test_move_assign<small1, small2>();
96 test_move_assign<large1, large2>();
97 test_move_assign<small, large>();
98 test_move_assign<large, small>();
99 test_move_assign_empty<small>();
100 test_move_assign_empty<large>();
102 return 0;