llvm-project
276 строк · 7.4 Кб
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// <map>
12
13// class multimap
14
15// multimap(multimap&& m, const allocator_type& a);
16
17#include <map>18#include <cassert>19
20#include "test_macros.h"21#include "MoveOnly.h"22#include "../../../test_compare.h"23#include "test_allocator.h"24#include "min_allocator.h"25#include "Counter.h"26
27int main(int, char**)28{
29{30typedef std::pair<MoveOnly, MoveOnly> V;31typedef std::pair<const MoveOnly, MoveOnly> VC;32typedef test_less<MoveOnly> C;33typedef test_allocator<VC> A;34typedef std::multimap<MoveOnly, MoveOnly, C, A> M;35typedef std::move_iterator<V*> I;36V a1[] =37{38V(1, 1),39V(1, 2),40V(1, 3),41V(2, 1),42V(2, 2),43V(2, 3),44V(3, 1),45V(3, 2),46V(3, 3)47};48M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));49V a2[] =50{51V(1, 1),52V(1, 2),53V(1, 3),54V(2, 1),55V(2, 2),56V(2, 3),57V(3, 1),58V(3, 2),59V(3, 3)60};61M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));62M m3(std::move(m1), A(7));63assert(m3 == m2);64assert(m3.get_allocator() == A(7));65assert(m3.key_comp() == C(5));66LIBCPP_ASSERT(m1.empty());67}68{69typedef std::pair<MoveOnly, MoveOnly> V;70typedef std::pair<const MoveOnly, MoveOnly> VC;71typedef test_less<MoveOnly> C;72typedef test_allocator<VC> A;73typedef std::multimap<MoveOnly, MoveOnly, C, A> M;74typedef std::move_iterator<V*> I;75V a1[] =76{77V(1, 1),78V(1, 2),79V(1, 3),80V(2, 1),81V(2, 2),82V(2, 3),83V(3, 1),84V(3, 2),85V(3, 3)86};87M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));88V a2[] =89{90V(1, 1),91V(1, 2),92V(1, 3),93V(2, 1),94V(2, 2),95V(2, 3),96V(3, 1),97V(3, 2),98V(3, 3)99};100M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));101M m3(std::move(m1), A(5));102assert(m3 == m2);103assert(m3.get_allocator() == A(5));104assert(m3.key_comp() == C(5));105LIBCPP_ASSERT(m1.empty());106}107{108typedef std::pair<MoveOnly, MoveOnly> V;109typedef std::pair<const MoveOnly, MoveOnly> VC;110typedef test_less<MoveOnly> C;111typedef other_allocator<VC> A;112typedef std::multimap<MoveOnly, MoveOnly, C, A> M;113typedef std::move_iterator<V*> I;114V a1[] =115{116V(1, 1),117V(1, 2),118V(1, 3),119V(2, 1),120V(2, 2),121V(2, 3),122V(3, 1),123V(3, 2),124V(3, 3)125};126M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));127V a2[] =128{129V(1, 1),130V(1, 2),131V(1, 3),132V(2, 1),133V(2, 2),134V(2, 3),135V(3, 1),136V(3, 2),137V(3, 3)138};139M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));140M m3(std::move(m1), A(5));141assert(m3 == m2);142assert(m3.get_allocator() == A(5));143assert(m3.key_comp() == C(5));144LIBCPP_ASSERT(m1.empty());145}146{147typedef Counter<int> T;148typedef std::pair<int, T> V;149typedef std::pair<const int, T> VC;150typedef test_allocator<VC> A;151typedef std::less<int> C;152typedef std::multimap<const int, T, C, A> M;153typedef V* I;154Counter_base::gConstructed = 0;155{156V a1[] =157{158V(1, 1),159V(1, 2),160V(1, 3),161V(2, 1),162V(2, 2),163V(2, 3),164V(3, 1),165V(3, 2),166V(3, 3)167};168const std::size_t num = sizeof(a1)/sizeof(a1[0]);169assert(Counter_base::gConstructed == num);170
171M m1(I(a1), I(a1+num), C(), A());172assert(Counter_base::gConstructed == 2*num);173
174M m2(m1);175assert(m2 == m1);176assert(Counter_base::gConstructed == 3*num);177
178M m3(std::move(m1), A());179assert(m3 == m2);180LIBCPP_ASSERT(m1.empty());181assert(Counter_base::gConstructed >= (int)(3*num));182assert(Counter_base::gConstructed <= (int)(4*num));183
184{185M m4(std::move(m2), A(5));186assert(Counter_base::gConstructed >= (int)(3*num));187assert(Counter_base::gConstructed <= (int)(5*num));188assert(m4 == m3);189LIBCPP_ASSERT(m2.empty());190}191assert(Counter_base::gConstructed >= (int)(2*num));192assert(Counter_base::gConstructed <= (int)(4*num));193}194assert(Counter_base::gConstructed == 0);195}196{197typedef std::pair<MoveOnly, MoveOnly> V;198typedef std::pair<const MoveOnly, MoveOnly> VC;199typedef test_less<MoveOnly> C;200typedef min_allocator<VC> A;201typedef std::multimap<MoveOnly, MoveOnly, C, A> M;202typedef std::move_iterator<V*> I;203V a1[] =204{205V(1, 1),206V(1, 2),207V(1, 3),208V(2, 1),209V(2, 2),210V(2, 3),211V(3, 1),212V(3, 2),213V(3, 3)214};215M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A());216V a2[] =217{218V(1, 1),219V(1, 2),220V(1, 3),221V(2, 1),222V(2, 2),223V(2, 3),224V(3, 1),225V(3, 2),226V(3, 3)227};228M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A());229M m3(std::move(m1), A());230assert(m3 == m2);231assert(m3.get_allocator() == A());232assert(m3.key_comp() == C(5));233LIBCPP_ASSERT(m1.empty());234}235{236typedef std::pair<MoveOnly, MoveOnly> V;237typedef std::pair<const MoveOnly, MoveOnly> VC;238typedef test_less<MoveOnly> C;239typedef explicit_allocator<VC> A;240typedef std::multimap<MoveOnly, MoveOnly, C, A> M;241typedef std::move_iterator<V*> I;242V a1[] =243{244V(1, 1),245V(1, 2),246V(1, 3),247V(2, 1),248V(2, 2),249V(2, 3),250V(3, 1),251V(3, 2),252V(3, 3)253};254M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A{});255V a2[] =256{257V(1, 1),258V(1, 2),259V(1, 3),260V(2, 1),261V(2, 2),262V(2, 3),263V(3, 1),264V(3, 2),265V(3, 3)266};267M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A{});268M m3(std::move(m1), A{});269assert(m3 == m2);270assert(m3.get_allocator() == A{});271assert(m3.key_comp() == C(5));272LIBCPP_ASSERT(m1.empty());273}274
275return 0;276}
277