llvm-project
150 строк · 5.7 Кб
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// template <class... Args>
16// iterator emplace(Args&&... args);
17
18#include <map>19#include <cassert>20
21#include "test_macros.h"22#include "../../../Emplaceable.h"23#include "DefaultOnly.h"24#include "min_allocator.h"25
26int main(int, char**)27{
28{29typedef std::multimap<int, DefaultOnly> M;30typedef M::iterator R;31M m;32assert(DefaultOnly::count == 0);33R r = m.emplace();34assert(r == m.begin());35assert(m.size() == 1);36assert(m.begin()->first == 0);37assert(m.begin()->second == DefaultOnly());38assert(DefaultOnly::count == 1);39r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1),40std::forward_as_tuple());41assert(r == std::next(m.begin()));42assert(m.size() == 2);43assert(std::next(m.begin())->first == 1);44assert(std::next(m.begin())->second == DefaultOnly());45assert(DefaultOnly::count == 2);46r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1),47std::forward_as_tuple());48assert(r == std::next(m.begin(), 2));49assert(m.size() == 3);50assert(std::next(m.begin(), 2)->first == 1);51assert(std::next(m.begin(), 2)->second == DefaultOnly());52assert(DefaultOnly::count == 3);53}54assert(DefaultOnly::count == 0);55{56typedef std::multimap<int, Emplaceable> M;57typedef M::iterator R;58M m;59R r = m.emplace(std::piecewise_construct, std::forward_as_tuple(2),60std::forward_as_tuple());61assert(r == m.begin());62assert(m.size() == 1);63assert(m.begin()->first == 2);64assert(m.begin()->second == Emplaceable());65r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1),66std::forward_as_tuple(2, 3.5));67assert(r == m.begin());68assert(m.size() == 2);69assert(m.begin()->first == 1);70assert(m.begin()->second == Emplaceable(2, 3.5));71r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1),72std::forward_as_tuple(3, 3.5));73assert(r == std::next(m.begin()));74assert(m.size() == 3);75assert(r->first == 1);76assert(r->second == Emplaceable(3, 3.5));77}78{79typedef std::multimap<int, double> M;80typedef M::iterator R;81M m;82R r = m.emplace(M::value_type(2, 3.5));83assert(r == m.begin());84assert(m.size() == 1);85assert(m.begin()->first == 2);86assert(m.begin()->second == 3.5);87}88{89typedef std::multimap<int, DefaultOnly, std::less<int>, min_allocator<std::pair<const int, DefaultOnly>>> M;90typedef M::iterator R;91M m;92assert(DefaultOnly::count == 0);93R r = m.emplace();94assert(r == m.begin());95assert(m.size() == 1);96assert(m.begin()->first == 0);97assert(m.begin()->second == DefaultOnly());98assert(DefaultOnly::count == 1);99r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1),100std::forward_as_tuple());101assert(r == std::next(m.begin()));102assert(m.size() == 2);103assert(std::next(m.begin())->first == 1);104assert(std::next(m.begin())->second == DefaultOnly());105assert(DefaultOnly::count == 2);106r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1),107std::forward_as_tuple());108assert(r == std::next(m.begin(), 2));109assert(m.size() == 3);110assert(std::next(m.begin(), 2)->first == 1);111assert(std::next(m.begin(), 2)->second == DefaultOnly());112assert(DefaultOnly::count == 3);113}114assert(DefaultOnly::count == 0);115{116typedef std::multimap<int, Emplaceable, std::less<int>, min_allocator<std::pair<const int, Emplaceable>>> M;117typedef M::iterator R;118M m;119R r = m.emplace(std::piecewise_construct, std::forward_as_tuple(2),120std::forward_as_tuple());121assert(r == m.begin());122assert(m.size() == 1);123assert(m.begin()->first == 2);124assert(m.begin()->second == Emplaceable());125r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1),126std::forward_as_tuple(2, 3.5));127assert(r == m.begin());128assert(m.size() == 2);129assert(m.begin()->first == 1);130assert(m.begin()->second == Emplaceable(2, 3.5));131r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1),132std::forward_as_tuple(3, 3.5));133assert(r == std::next(m.begin()));134assert(m.size() == 3);135assert(r->first == 1);136assert(r->second == Emplaceable(3, 3.5));137}138{139typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;140typedef M::iterator R;141M m;142R r = m.emplace(M::value_type(2, 3.5));143assert(r == m.begin());144assert(m.size() == 1);145assert(m.begin()->first == 2);146assert(m.begin()->second == 3.5);147}148
149return 0;150}
151