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_iterator position, const value_type& v);
14
15#include <flat_set>
16#include <cassert>
17#include <functional>
18#include <deque>
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_set<Key, std::less<Key>, KeyContainer>;
29 using R = typename M::iterator;
30 using VT = typename M::value_type;
31
32 M m;
33 const VT v1(2);
34 std::same_as<R> decltype(auto) r = m.insert(m.end(), 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(m.end(), 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(m.end(), 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(m.end(), v4);
53 assert(r == std::ranges::prev(m.end()));
54 assert(m.size() == 3);
55 assert(*r == 3);
56}
57
58void test() {
59 test_one<std::vector<int>>();
60 test_one<std::deque<int>>();
61 test_one<MinSequenceContainer<int>>();
62 test_one<std::vector<int, min_allocator<int>>>();
63}
64
65void test_exception() {
66 auto insert_func = [](auto& m, auto key_arg) {
67 using FlatSet = std::decay_t<decltype(m)>;
68 using value_type = typename FlatSet::value_type;
69 const value_type p(key_arg);
70 m.insert(m.begin(), p);
71 };
72 test_emplace_exception_guarantee(emplace_function&: insert_func);
73}
74
75int main(int, char**) {
76 test();
77 test_exception();
78
79 return 0;
80}
81

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