llvm-project
190 строк · 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// <map>
12
13// class multimap
14
15// multimap& operator=(multimap&& m);
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
26int main(int, char**)27{
28{29typedef std::pair<MoveOnly, MoveOnly> V;30typedef std::pair<const MoveOnly, MoveOnly> VC;31typedef test_less<MoveOnly> C;32typedef test_allocator<VC> A;33typedef std::multimap<MoveOnly, MoveOnly, C, A> M;34typedef std::move_iterator<V*> I;35V a1[] =36{37V(1, 1),38V(1, 2),39V(1, 3),40V(2, 1),41V(2, 2),42V(2, 3),43V(3, 1),44V(3, 2),45V(3, 3)46};47M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));48V a2[] =49{50V(1, 1),51V(1, 2),52V(1, 3),53V(2, 1),54V(2, 2),55V(2, 3),56V(3, 1),57V(3, 2),58V(3, 3)59};60M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));61M m3(C(3), A(7));62m3 = std::move(m1);63assert(m3 == m2);64assert(m3.get_allocator() == A(7));65assert(m3.key_comp() == C(5));66assert(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(C(3), A(5));102m3 = std::move(m1);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::multimap<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(C(3), A(5));142m3 = std::move(m1);143assert(m3 == m2);144assert(m3.get_allocator() == A(7));145assert(m3.key_comp() == C(5));146assert(m1.empty());147}148{149typedef std::pair<MoveOnly, MoveOnly> V;150typedef std::pair<const MoveOnly, MoveOnly> VC;151typedef test_less<MoveOnly> C;152typedef min_allocator<VC> A;153typedef std::multimap<MoveOnly, MoveOnly, C, A> M;154typedef std::move_iterator<V*> I;155V a1[] =156{157V(1, 1),158V(1, 2),159V(1, 3),160V(2, 1),161V(2, 2),162V(2, 3),163V(3, 1),164V(3, 2),165V(3, 3)166};167M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A());168V a2[] =169{170V(1, 1),171V(1, 2),172V(1, 3),173V(2, 1),174V(2, 2),175V(2, 3),176V(3, 1),177V(3, 2),178V(3, 3)179};180M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A());181M m3(C(3), A());182m3 = std::move(m1);183assert(m3 == m2);184assert(m3.get_allocator() == A());185assert(m3.key_comp() == C(5));186assert(m1.empty());187}188
189return 0;190}
191