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// void insert(initializer_list<value_type> il);
14
15#include <flat_map>
16#include <cassert>
17#include <functional>
18#include <deque>
19
20#include "MinSequenceContainer.h"
21#include "../helpers.h"
22#include "test_macros.h"
23#include "min_allocator.h"
24
25template <class KeyContainer, class ValueContainer>
26void test() {
27 using Key = typename KeyContainer::value_type;
28 using Value = typename ValueContainer::value_type;
29 using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
30 using V = std::pair<const int, double>;
31
32 M m = {{1, 1}, {1, 1.5}, {1, 2}, {3, 1}, {3, 1.5}, {3, 2}};
33 m.insert({
34 {4, 1},
35 {4, 1.5},
36 {4, 2},
37 {1, 1},
38 {1, 1.5},
39 {1, 2},
40 {2, 1},
41 {2, 1.5},
42 {2, 2},
43 });
44 assert(m.size() == 4);
45 assert(std::distance(m.begin(), m.end()) == 4);
46 assert(*m.begin() == V(1, 1));
47 assert(*std::next(m.begin()) == V(2, 1));
48 assert(*std::next(m.begin(), 2) == V(3, 1));
49 assert(*std::next(m.begin(), 3) == V(4, 1));
50}
51
52int main(int, char**) {
53 test<std::vector<int>, std::vector<double>>();
54 test<std::deque<int>, std::vector<double>>();
55 test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
56 test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
57
58 {
59 auto insert_func = [](auto& m, const auto& newValues) {
60 using FlatMap = std::decay_t<decltype(m)>;
61 using value_type = typename FlatMap::value_type;
62 std::initializer_list<value_type> il = {{newValues[0].first, newValues[0].second}};
63 m.insert(il);
64 };
65 test_insert_range_exception_guarantee(insert_function&: insert_func);
66 }
67 return 0;
68}
69

source code of libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_initializer_list.pass.cpp