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 | // pair<iterator, bool> insert(const value_type& v); |
14 | |
15 | #include <set> |
16 | #include <cassert> |
17 | |
18 | #include "test_macros.h" |
19 | #include "min_allocator.h" |
20 | |
21 | template <class Container> |
22 | void do_insert_cv_test() { |
23 | typedef Container M; |
24 | typedef std::pair<typename M::iterator, bool> R; |
25 | typedef typename M::value_type VT; |
26 | M m; |
27 | |
28 | const VT v1(2); |
29 | R r = m.insert(v1); |
30 | assert(r.second); |
31 | assert(r.first == m.begin()); |
32 | assert(m.size() == 1); |
33 | assert(*r.first == 2); |
34 | |
35 | const VT v2(1); |
36 | r = m.insert(v2); |
37 | assert(r.second); |
38 | assert(r.first == m.begin()); |
39 | assert(m.size() == 2); |
40 | assert(*r.first == 1); |
41 | |
42 | const VT v3(3); |
43 | r = m.insert(v3); |
44 | assert(r.second); |
45 | assert(r.first == std::prev(m.end())); |
46 | assert(m.size() == 3); |
47 | assert(*r.first == 3); |
48 | |
49 | r = m.insert(v3); |
50 | assert(!r.second); |
51 | assert(r.first == std::prev(m.end())); |
52 | assert(m.size() == 3); |
53 | assert(*r.first == 3); |
54 | } |
55 | |
56 | int main(int, char**) { |
57 | do_insert_cv_test<std::set<int> >(); |
58 | #if TEST_STD_VER >= 11 |
59 | { |
60 | typedef std::set<int, std::less<int>, min_allocator<int>> M; |
61 | do_insert_cv_test<M>(); |
62 | } |
63 | #endif |
64 | |
65 | return 0; |
66 | } |
67 | |