1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
16 // iterator insert(const_iterator position, P&& p);
22 #include "min_allocator.h"
23 #include "test_macros.h"
25 template <class Container
, class Pair
>
26 void do_insert_rv_test()
30 typedef typename
M::iterator R
;
32 R r
= m
.insert(m
.cend(), P(2, 2));
33 assert(r
== m
.begin());
34 assert(m
.size() == 1);
35 assert(r
->first
== 2);
36 assert(r
->second
== 2);
38 r
= m
.insert(m
.cend(), P(1, 1));
39 assert(r
== m
.begin());
40 assert(m
.size() == 2);
41 assert(r
->first
== 1);
42 assert(r
->second
== 1);
44 r
= m
.insert(m
.cend(), 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);
50 r
= m
.insert(m
.cend(), P(3, 2));
51 assert(r
== std::prev(m
.end()));
52 assert(m
.size() == 4);
53 assert(r
->first
== 3);
54 assert(r
->second
== 2);
59 do_insert_rv_test
<std::multimap
<int, MoveOnly
>, std::pair
<int, MoveOnly
> >();
60 do_insert_rv_test
<std::multimap
<int, MoveOnly
>, std::pair
<const int, MoveOnly
> >();
63 typedef std::multimap
<int, MoveOnly
, std::less
<int>, min_allocator
<std::pair
<const int, MoveOnly
>>> M
;
64 typedef std::pair
<int, MoveOnly
> P
;
65 typedef std::pair
<const int, MoveOnly
> CP
;
66 do_insert_rv_test
<M
, P
>();
67 do_insert_rv_test
<M
, CP
>();
71 typedef std::multimap
<int, MoveOnly
> M
;
72 typedef M::iterator R
;
74 R r
= m
.insert(m
.cend(), {2, MoveOnly(2)});
75 assert(r
== m
.begin());
76 assert(m
.size() == 1);
77 assert(r
->first
== 2);
78 assert(r
->second
== 2);
80 r
= m
.insert(m
.cend(), {1, MoveOnly(1)});
81 assert(r
== m
.begin());
82 assert(m
.size() == 2);
83 assert(r
->first
== 1);
84 assert(r
->second
== 1);
86 r
= m
.insert(m
.cend(), {3, MoveOnly(3)});
87 assert(r
== std::prev(m
.end()));
88 assert(m
.size() == 3);
89 assert(r
->first
== 3);
90 assert(r
->second
== 3);
92 r
= m
.insert(m
.cend(), {3, MoveOnly(2)});
93 assert(r
== std::prev(m
.end()));
94 assert(m
.size() == 4);
95 assert(r
->first
== 3);
96 assert(r
->second
== 2);