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// template <class P>
16// iterator insert(const_iterator position, 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, class Pair>
26void do_insert_iter_rv_test()
27{
28 typedef Container M;
29 typedef Pair P;
30 typedef typename M::iterator R;
31 M m;
32 R r = m.insert(m.end(), P(2, 2));
33 assert(r == m.begin());
34 assert(m.size() == 1);
35 assert(r->first == 2);
36 assert(r->second == 2);
37
38 r = m.insert(m.end(), P(1, 1));
39 assert(r == m.begin());
40 assert(m.size() == 2);
41 assert(r->first == 1);
42 assert(r->second == 1);
43
44 r = m.insert(m.end(), P(3, 3));
45 assert(r == std::prev(m.end()));
46 assert(m.size() == 3);
47 assert(r->first == 3);
48 assert(r->second == 3);
49
50 r = m.insert(m.end(), P(3, 4));
51 assert(r == std::prev(m.end()));
52 assert(m.size() == 3);
53 assert(r->first == 3);
54 assert(r->second == 3);
55}
56int main(int, char**)
57{
58 do_insert_iter_rv_test<std::map<int, MoveOnly>, std::pair<int, MoveOnly>>();
59 do_insert_iter_rv_test<std::map<int, MoveOnly>, std::pair<const int, MoveOnly>>();
60
61 {
62 typedef std::map<int, MoveOnly, std::less<int>, min_allocator<std::pair<const int, MoveOnly>>> M;
63 typedef std::pair<int, MoveOnly> P;
64 typedef std::pair<const int, MoveOnly> CP;
65 do_insert_iter_rv_test<M, P>();
66 do_insert_iter_rv_test<M, CP>();
67 }
68 {
69 typedef std::map<int, MoveOnly> M;
70 typedef M::iterator R;
71 M m;
72 R r = m.insert(m.end(), {2, MoveOnly(2)});
73 assert(r == m.begin());
74 assert(m.size() == 1);
75 assert(r->first == 2);
76 assert(r->second == 2);
77
78 r = m.insert(m.end(), {1, MoveOnly(1)});
79 assert(r == m.begin());
80 assert(m.size() == 2);
81 assert(r->first == 1);
82 assert(r->second == 1);
83
84 r = m.insert(m.end(), {3, MoveOnly(3)});
85 assert(r == std::prev(m.end()));
86 assert(m.size() == 3);
87 assert(r->first == 3);
88 assert(r->second == 3);
89
90 r = m.insert(m.end(), {3, MoveOnly(3)});
91 assert(r == std::prev(m.end()));
92 assert(m.size() == 3);
93 assert(r->first == 3);
94 assert(r->second == 3);
95 }
96
97
98 return 0;
99}
100

source code of libcxx/test/std/containers/associative/map/map.modifiers/insert_iter_rv.pass.cpp