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 "min_allocator.h"
19 
20 template<class Container>
21 void do_insert_cv_test()
22 {
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 == 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 == prev(m.end()));
52     assert(m.size() == 3);
53     assert(*r.first == 3);
54 }
55 
56 int main(int, char**)
57 {
58     do_insert_cv_test<std::set<int> >();
59 #if TEST_STD_VER >= 11
60     {
61         typedef std::set<int, std::less<int>, min_allocator<int>> M;
62         do_insert_cv_test<M>();
63     }
64 #endif
65 
66   return 0;
67 }
68