116 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++0310 11// <set>12 13// class set14 15// set(set&& s, const allocator_type& a);16 17#include <set>18#include <cassert>19#include <iterator>20 21#include "test_macros.h"22#include "MoveOnly.h"23#include "../../../test_compare.h"24#include "test_allocator.h"25#include "Counter.h"26 27int main(int, char**) {28 {29 typedef MoveOnly V;30 typedef test_less<MoveOnly> C;31 typedef test_allocator<V> A;32 typedef std::set<MoveOnly, C, A> M;33 typedef std::move_iterator<V*> I;34 V a1[] = {V(1), V(1), V(1), V(2), V(2), V(2), V(3), V(3), V(3)};35 M m1(I(a1), I(a1 + sizeof(a1) / sizeof(a1[0])), C(5), A(7));36 V a2[] = {V(1), V(1), V(1), V(2), V(2), V(2), V(3), V(3), V(3)};37 M m2(I(a2), I(a2 + sizeof(a2) / sizeof(a2[0])), C(5), A(7));38 M m3(std::move(m1), A(7));39 assert(m3 == m2);40 assert(m3.get_allocator() == A(7));41 assert(m3.key_comp() == C(5));42 LIBCPP_ASSERT(m1.empty());43 }44 {45 typedef MoveOnly V;46 typedef test_less<MoveOnly> C;47 typedef test_allocator<V> A;48 typedef std::set<MoveOnly, C, A> M;49 typedef std::move_iterator<V*> I;50 V a1[] = {V(1), V(1), V(1), V(2), V(2), V(2), V(3), V(3), V(3)};51 M m1(I(a1), I(a1 + sizeof(a1) / sizeof(a1[0])), C(5), A(7));52 V a2[] = {V(1), V(1), V(1), V(2), V(2), V(2), V(3), V(3), V(3)};53 M m2(I(a2), I(a2 + sizeof(a2) / sizeof(a2[0])), C(5), A(7));54 M m3(std::move(m1), A(5));55 assert(m3 == m2);56 assert(m3.get_allocator() == A(5));57 assert(m3.key_comp() == C(5));58 LIBCPP_ASSERT(m1.empty());59 }60 {61 typedef MoveOnly V;62 typedef test_less<MoveOnly> C;63 typedef other_allocator<V> A;64 typedef std::set<MoveOnly, C, A> M;65 typedef std::move_iterator<V*> I;66 V a1[] = {V(1), V(1), V(1), V(2), V(2), V(2), V(3), V(3), V(3)};67 M m1(I(a1), I(a1 + sizeof(a1) / sizeof(a1[0])), C(5), A(7));68 V a2[] = {V(1), V(1), V(1), V(2), V(2), V(2), V(3), V(3), V(3)};69 M m2(I(a2), I(a2 + sizeof(a2) / sizeof(a2[0])), C(5), A(7));70 M m3(std::move(m1), A(5));71 assert(m3 == m2);72 assert(m3.get_allocator() == A(5));73 assert(m3.key_comp() == C(5));74 LIBCPP_ASSERT(m1.empty());75 }76 {77 typedef Counter<int> V;78 typedef std::less<V> C;79 typedef test_allocator<V> A;80 typedef std::set<V, C, A> M;81 typedef V* I;82 Counter_base::gConstructed = 0;83 {84 V a1[] = {V(1), V(1), V(1), V(2), V(2), V(2), V(3), V(3), V(3)};85 const std::size_t num = sizeof(a1) / sizeof(a1[0]);86 assert(Counter_base::gConstructed == num);87 88 M m1(I(a1), I(a1 + num), C(), A());89 assert(Counter_base::gConstructed == 3 + num);90 91 M m2(m1);92 assert(m2 == m1);93 assert(Counter_base::gConstructed == 6 + num);94 95 M m3(std::move(m1), A());96 assert(m3 == m2);97 LIBCPP_ASSERT(m1.empty());98 assert(Counter_base::gConstructed >= (int)(6 + num));99 assert(Counter_base::gConstructed <= (int)(m1.size() + 6 + num));100 101 {102 M m4(std::move(m2), A(5));103 assert(Counter_base::gConstructed >= (int)(6 + num));104 assert(Counter_base::gConstructed <= (int)(m1.size() + m2.size() + 6 + num));105 assert(m4 == m3);106 LIBCPP_ASSERT(m2.empty());107 }108 assert(Counter_base::gConstructed >= (int)(3 + num));109 assert(Counter_base::gConstructed <= (int)(m1.size() + m2.size() + 3 + num));110 }111 assert(Counter_base::gConstructed == 0);112 }113 114 return 0;115}116