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