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 | // <set> |
10 | |
11 | // class set |
12 | |
13 | // iterator insert(const_iterator position, const value_type& v); |
14 | |
15 | #include <set> |
16 | #include <cassert> |
17 | |
18 | #include "test_macros.h" |
19 | #include "min_allocator.h" |
20 | |
21 | int main(int, char**) |
22 | { |
23 | { |
24 | typedef std::set<int> M; |
25 | typedef M::iterator R; |
26 | M m; |
27 | R r = m.insert(position: m.cend(), x: M::value_type(2)); |
28 | assert(r == m.begin()); |
29 | assert(m.size() == 1); |
30 | assert(*r == 2); |
31 | |
32 | r = m.insert(position: m.cend(), x: M::value_type(1)); |
33 | assert(r == m.begin()); |
34 | assert(m.size() == 2); |
35 | assert(*r == 1); |
36 | |
37 | r = m.insert(position: m.cend(), x: M::value_type(3)); |
38 | assert(r == std::prev(m.end())); |
39 | assert(m.size() == 3); |
40 | assert(*r == 3); |
41 | |
42 | r = m.insert(position: m.cend(), x: M::value_type(3)); |
43 | assert(r == std::prev(m.end())); |
44 | assert(m.size() == 3); |
45 | assert(*r == 3); |
46 | } |
47 | #if TEST_STD_VER >= 11 |
48 | { |
49 | typedef std::set<int, std::less<int>, min_allocator<int>> M; |
50 | typedef M::iterator R; |
51 | M m; |
52 | R r = m.insert(m.cend(), M::value_type(2)); |
53 | assert(r == m.begin()); |
54 | assert(m.size() == 1); |
55 | assert(*r == 2); |
56 | |
57 | r = m.insert(m.cend(), M::value_type(1)); |
58 | assert(r == m.begin()); |
59 | assert(m.size() == 2); |
60 | assert(*r == 1); |
61 | |
62 | r = m.insert(m.cend(), M::value_type(3)); |
63 | assert(r == std::prev(m.end())); |
64 | assert(m.size() == 3); |
65 | assert(*r == 3); |
66 | |
67 | r = m.insert(m.cend(), M::value_type(3)); |
68 | assert(r == std::prev(m.end())); |
69 | assert(m.size() == 3); |
70 | assert(*r == 3); |
71 | } |
72 | #endif |
73 | |
74 | return 0; |
75 | } |
76 | |