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_set>
12
13// void insert(initializer_list<value_type> il);
14
15#include <flat_set>
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>
26void test_one() {
27 using Key = typename KeyContainer::value_type;
28 using M = std::flat_multiset<Key, std::less<Key>, KeyContainer>;
29
30 {
31 M m = {1, 1, 1, 3, 3, 3};
32 m.insert({
33 4,
34 4,
35 4,
36 1,
37 1,
38 1,
39 2,
40 2,
41 2,
42 });
43 assert(m.size() == 15);
44
45 KeyContainer expected{1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4};
46 assert(std::ranges::equal(m, expected));
47 }
48 {
49 // was empty
50 M m;
51 m.insert({
52 4,
53 4,
54 4,
55 1,
56 1,
57 1,
58 2,
59 2,
60 2,
61 });
62 assert(m.size() == 9);
63 KeyContainer expected{1, 1, 1, 2, 2, 2, 4, 4, 4};
64 assert(std::ranges::equal(m, expected));
65 }
66}
67
68void test() {
69 test_one<std::vector<int>>();
70 test_one<std::deque<int>>();
71 test_one<MinSequenceContainer<int>>();
72 test_one<std::vector<int, min_allocator<int>>>();
73}
74
75void test_exception() {
76 auto insert_func = [](auto& m, const auto& newValues) {
77 using FlatSet = std::decay_t<decltype(m)>;
78 using value_type = typename FlatSet::value_type;
79 std::initializer_list<value_type> il = {newValues[0]};
80 m.insert(il);
81 };
82 test_insert_range_exception_guarantee(insert_function&: insert_func);
83}
84
85int main(int, char**) {
86 test();
87 test_exception();
88
89 return 0;
90}
91

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