llvm-project
193 строки · 4.8 Кб
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//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: c++03
10
11// <set>
12
13// class multiset
14
15// multiset(multiset&& 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{30typedef MoveOnly V;31typedef test_less<MoveOnly> C;32typedef test_allocator<V> A;33typedef std::multiset<MoveOnly, C, A> M;34typedef std::move_iterator<V*> I;35V a1[] =36{37V(1),38V(1),39V(1),40V(2),41V(2),42V(2),43V(3),44V(3),45V(3)46};47M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));48V a2[] =49{50V(1),51V(1),52V(1),53V(2),54V(2),55V(2),56V(3),57V(3),58V(3)59};60M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));61M m3(std::move(m1), A(7));62assert(m3 == m2);63assert(m3.get_allocator() == A(7));64assert(m3.key_comp() == C(5));65LIBCPP_ASSERT(m1.empty());66}67{68typedef MoveOnly V;69typedef test_less<MoveOnly> C;70typedef test_allocator<V> A;71typedef std::multiset<MoveOnly, C, A> M;72typedef std::move_iterator<V*> I;73V a1[] =74{75V(1),76V(1),77V(1),78V(2),79V(2),80V(2),81V(3),82V(3),83V(3)84};85M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));86V a2[] =87{88V(1),89V(1),90V(1),91V(2),92V(2),93V(2),94V(3),95V(3),96V(3)97};98M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));99M m3(std::move(m1), A(5));100assert(m3 == m2);101assert(m3.get_allocator() == A(5));102assert(m3.key_comp() == C(5));103LIBCPP_ASSERT(m1.empty());104}105{106typedef MoveOnly V;107typedef test_less<MoveOnly> C;108typedef other_allocator<V> A;109typedef std::multiset<MoveOnly, C, A> M;110typedef std::move_iterator<V*> I;111V a1[] =112{113V(1),114V(1),115V(1),116V(2),117V(2),118V(2),119V(3),120V(3),121V(3)122};123M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));124V a2[] =125{126V(1),127V(1),128V(1),129V(2),130V(2),131V(2),132V(3),133V(3),134V(3)135};136M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));137M m3(std::move(m1), A(5));138assert(m3 == m2);139assert(m3.get_allocator() == A(5));140assert(m3.key_comp() == C(5));141LIBCPP_ASSERT(m1.empty());142}143{144typedef Counter<int> V;145typedef std::less<V> C;146typedef test_allocator<V> A;147typedef std::multiset<V, C, A> M;148typedef V* I;149Counter_base::gConstructed = 0;150{151V a1[] =152{153V(1),154V(1),155V(1),156V(2),157V(2),158V(2),159V(3),160V(3),161V(3)162};163const std::size_t num = sizeof(a1)/sizeof(a1[0]);164assert(Counter_base::gConstructed == num);165
166M m1(I(a1), I(a1+num), C(), A());167assert(Counter_base::gConstructed == 2*num);168
169M m2(m1);170assert(m2 == m1);171assert(Counter_base::gConstructed == 3*num);172
173M m3(std::move(m1), A());174assert(m3 == m2);175LIBCPP_ASSERT(m1.empty());176assert(Counter_base::gConstructed >= (int)(3*num));177assert(Counter_base::gConstructed <= (int)(4*num));178
179{180M m4(std::move(m2), A(5));181assert(Counter_base::gConstructed >= (int)(3*num));182assert(Counter_base::gConstructed <= (int)(5*num));183assert(m4 == m3);184LIBCPP_ASSERT(m2.empty());185}186assert(Counter_base::gConstructed >= (int)(2*num));187assert(Counter_base::gConstructed <= (int)(4*num));188}189assert(Counter_base::gConstructed == 0);190}191
192return 0;193}
194