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 value_type& v);
16
17#include <flat_map>
18#include <deque>
19#include <cassert>
20#include <functional>
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 M m;
35
36 const VT v1(2, 2.5);
37 std::same_as<R> decltype(auto) r = m.insert(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(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(v3);
52 assert(r == m.begin() + 2);
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(v4);
59 assert(r == m.begin() + 3);
60 assert(m.size() == 4);
61 assert(r->first == 3);
62 assert(r->second == 4.5);
63}
64
65int main(int, char**) {
66 test<std::vector<int>, std::vector<double>>();
67 test<std::deque<int>, std::vector<double>>();
68 test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
69 test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
70
71 {
72 auto insert_func = [](auto& m, auto key_arg, auto value_arg) {
73 using FlatMap = std::decay_t<decltype(m)>;
74 using value_type = typename FlatMap::value_type;
75 const value_type p(std::piecewise_construct, std::tuple(key_arg), std::tuple(value_arg));
76 m.insert(p);
77 };
78 test_emplace_exception_guarantee(emplace_function&: insert_func);
79 }
80 return 0;
81}
82

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