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 //===----------------------------------------------------------------------===//
15 // pair<iterator, bool> insert( value_type&& v); // C++17 and later
17 // pair<iterator, bool> insert(P&& p);
23 #include "min_allocator.h"
24 #include "test_macros.h"
26 template <class Container
, class Pair
>
27 void do_insert_rv_test()
31 typedef std::pair
<typename
M::iterator
, bool> R
;
33 R r
= m
.insert(P(2, 2));
35 assert(r
.first
== m
.begin());
36 assert(m
.size() == 1);
37 assert(r
.first
->first
== 2);
38 assert(r
.first
->second
== 2);
40 r
= m
.insert(P(1, 1));
42 assert(r
.first
== m
.begin());
43 assert(m
.size() == 2);
44 assert(r
.first
->first
== 1);
45 assert(r
.first
->second
== 1);
47 r
= m
.insert(P(3, 3));
49 assert(r
.first
== std::prev(m
.end()));
50 assert(m
.size() == 3);
51 assert(r
.first
->first
== 3);
52 assert(r
.first
->second
== 3);
54 r
= m
.insert(P(3, 3));
56 assert(r
.first
== std::prev(m
.end()));
57 assert(m
.size() == 3);
58 assert(r
.first
->first
== 3);
59 assert(r
.first
->second
== 3);
64 do_insert_rv_test
<std::map
<int, MoveOnly
>, std::pair
<int, MoveOnly
>>();
65 do_insert_rv_test
<std::map
<int, MoveOnly
>, std::pair
<const int, MoveOnly
>>();
68 typedef std::map
<int, MoveOnly
, std::less
<int>, min_allocator
<std::pair
<const int, MoveOnly
>>> M
;
69 typedef std::pair
<int, MoveOnly
> P
;
70 typedef std::pair
<const int, MoveOnly
> CP
;
71 do_insert_rv_test
<M
, P
>();
72 do_insert_rv_test
<M
, CP
>();
75 typedef std::map
<int, MoveOnly
> M
;
76 typedef std::pair
<M::iterator
, bool> R
;
78 R r
= m
.insert({2, MoveOnly(2)});
80 assert(r
.first
== m
.begin());
81 assert(m
.size() == 1);
82 assert(r
.first
->first
== 2);
83 assert(r
.first
->second
== 2);
85 r
= m
.insert({1, MoveOnly(1)});
87 assert(r
.first
== m
.begin());
88 assert(m
.size() == 2);
89 assert(r
.first
->first
== 1);
90 assert(r
.first
->second
== 1);
92 r
= m
.insert({3, MoveOnly(3)});
94 assert(r
.first
== std::prev(m
.end()));
95 assert(m
.size() == 3);
96 assert(r
.first
->first
== 3);
97 assert(r
.first
->second
== 3);
99 r
= m
.insert({3, MoveOnly(3)});
101 assert(r
.first
== std::prev(m
.end()));
102 assert(m
.size() == 3);
103 assert(r
.first
->first
== 3);
104 assert(r
.first
->second
== 3);