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_iter_rv_test()
30 typedef typename
M::iterator R
;
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);
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);
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);
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);
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
>>();
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
>();
69 typedef std::map
<int, MoveOnly
> M
;
70 typedef M::iterator R
;
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);
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);
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);
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);