llvm-project
94 строки · 2.3 Кб
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 P>
16// iterator insert(P&& p);
17
18#include <map>
19#include <cassert>
20
21#include "MoveOnly.h"
22#include "min_allocator.h"
23#include "test_macros.h"
24
25template <class Container>
26void do_insert_rv_test()
27{
28typedef std::multimap<int, MoveOnly> M;
29typedef typename M::iterator R;
30typedef typename M::value_type VT;
31M m;
32R r = m.insert(VT(2, 2));
33assert(r == m.begin());
34assert(m.size() == 1);
35assert(r->first == 2);
36assert(r->second == 2);
37
38r = m.insert(VT(1, 1));
39assert(r == m.begin());
40assert(m.size() == 2);
41assert(r->first == 1);
42assert(r->second == 1);
43
44r = m.insert(VT(3, 3));
45assert(r == std::prev(m.end()));
46assert(m.size() == 3);
47assert(r->first == 3);
48assert(r->second == 3);
49
50r = m.insert(VT(3, 3));
51assert(r == std::prev(m.end()));
52assert(m.size() == 4);
53assert(r->first == 3);
54assert(r->second == 3);
55}
56
57int main(int, char**)
58{
59do_insert_rv_test<std::multimap<int, MoveOnly>>();
60{
61typedef std::multimap<int, MoveOnly, std::less<int>, min_allocator<std::pair<const int, MoveOnly>>> M;
62do_insert_rv_test<M>();
63}
64{
65typedef std::multimap<int, MoveOnly> M;
66typedef M::iterator R;
67M m;
68R r = m.insert({2, MoveOnly(2)});
69assert(r == m.begin());
70assert(m.size() == 1);
71assert(r->first == 2);
72assert(r->second == 2);
73
74r = m.insert({1, MoveOnly(1)});
75assert(r == m.begin());
76assert(m.size() == 2);
77assert(r->first == 1);
78assert(r->second == 1);
79
80r = m.insert({3, MoveOnly(3)});
81assert(r == std::prev(m.end()));
82assert(m.size() == 3);
83assert(r->first == 3);
84assert(r->second == 3);
85
86r = m.insert({3, MoveOnly(3)});
87assert(r == std::prev(m.end()));
88assert(m.size() == 4);
89assert(r->first == 3);
90assert(r->second == 3);
91}
92
93return 0;
94}
95