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, c++11, c++14, c++17, c++20
10
11// <flat_map>
12
13// class flat_multimap
14
15// iterator insert(const_iterator position, const value_type& v);
16
17#include <flat_map>
18#include <cassert>
19#include <functional>
20#include <deque>
21
22#include "MinSequenceContainer.h"
23#include "test_macros.h"
24#include "../helpers.h"
25#include "min_allocator.h"
26
27template <class KeyContainer, class ValueContainer>
28void test() {
29 using Key = typename KeyContainer::value_type;
30 using Value = typename ValueContainer::value_type;
31 using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
32 using R = typename M::iterator;
33 using VT = typename M::value_type;
34
35 M m;
36 const VT v1(2, 2.5);
37 std::same_as<R> decltype(auto) r = m.insert(m.end(), v1);
38 assert(r == m.begin());
39 assert(m.size() == 1);
40 assert(r->first == 2);
41 assert(r->second == 2.5);
42
43 const VT v2(1, 1.5);
44 r = m.insert(m.end(), v2);
45 assert(r == m.begin());
46 assert(m.size() == 2);
47 assert(r->first == 1);
48 assert(r->second == 1.5);
49
50 const VT v3(3, 3.5);
51 r = m.insert(m.end(), v3);
52 assert(r == std::ranges::prev(m.end()));
53 assert(m.size() == 3);
54 assert(r->first == 3);
55 assert(r->second == 3.5);
56
57 const VT v4(3, 4.5);
58 r = m.insert(m.end(), v4);
59 assert(r == std::ranges::prev(m.end()));
60 assert(m.size() == 4);
61 assert(r->first == 3);
62 assert(r->second == 4.5);
63
64 const VT v5(2, 5.5);
65 r = m.insert(m.end(), v5);
66 assert(r == m.begin() + 2);
67 assert(m.size() == 5);
68 assert(r->first == 2);
69 assert(r->second == 5.5);
70
71 const VT v6(2, 6.5);
72 r = m.insert(m.begin(), v6);
73 assert(r == m.begin() + 1);
74 assert(m.size() == 6);
75 assert(r->first == 2);
76 assert(r->second == 6.5);
77}
78
79int main(int, char**) {
80 test<std::vector<int>, std::vector<double>>();
81 test<std::deque<int>, std::vector<double>>();
82 test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
83 test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
84
85 {
86 auto insert_func = [](auto& m, auto key_arg, auto value_arg) {
87 using FlatMap = std::decay_t<decltype(m)>;
88 using value_type = typename FlatMap::value_type;
89 const value_type p(std::piecewise_construct, std::tuple(key_arg), std::tuple(value_arg));
90 m.insert(m.begin(), p);
91 };
92 test_emplace_exception_guarantee(emplace_function&: insert_func);
93 }
94 return 0;
95}
96

source code of libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.modifiers/insert_iter_cv.pass.cpp