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// iterator insert(const value_type& v);
14
15#include <flat_set>
16#include <deque>
17#include <cassert>
18#include <functional>
19
20#include "MinSequenceContainer.h"
21#include "test_macros.h"
22#include "../helpers.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 using R = typename M::iterator;
30 using VT = typename M::value_type;
31 M m;
32
33 const VT v1(2);
34 std::same_as<R> decltype(auto) r = m.insert(v1);
35 assert(r == m.begin());
36 assert(m.size() == 1);
37 assert(*r == 2);
38
39 const VT v2(1);
40 r = m.insert(v2);
41 assert(r == m.begin());
42 assert(m.size() == 2);
43 assert(*r == 1);
44
45 const VT v3(3);
46 r = m.insert(v3);
47 assert(r == std::ranges::prev(m.end()));
48 assert(m.size() == 3);
49 assert(*r == 3);
50
51 const VT v4(3);
52 r = m.insert(v4);
53 assert(r == std::ranges::prev(m.end()));
54 assert(m.size() == 4);
55 assert(*r == 3);
56
57 const VT v5(1);
58 r = m.insert(v5);
59 assert(r == m.begin() + 1);
60 assert(m.size() == 5);
61 assert(*r == 1);
62}
63
64void test() {
65 test_one<std::vector<int>>();
66 test_one<std::deque<int>>();
67 test_one<MinSequenceContainer<int>>();
68 test_one<std::vector<int, min_allocator<int>>>();
69}
70
71void test_exception() {
72 auto insert_func = [](auto& m, auto key_arg) {
73 using value_type = typename std::decay_t<decltype(m)>::value_type;
74 const value_type p(key_arg);
75 m.insert(p);
76 };
77 test_emplace_exception_guarantee(emplace_function&: insert_func);
78}
79
80int main(int, char**) {
81 test();
82 test_exception();
83
84 return 0;
85}
86

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