• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <set>
11 
12 // class set
13 
14 // pair<iterator, bool> insert(const value_type& v);
15 
16 #include <set>
17 #include <cassert>
18 
19 #include "min_allocator.h"
20 
21 template<class Container>
do_insert_cv_test()22 void do_insert_cv_test()
23 {
24     typedef Container M;
25     typedef std::pair<typename M::iterator, bool> R;
26     typedef typename M::value_type VT;
27     M m;
28 
29     const VT v1(2);
30     R r = m.insert(v1);
31     assert(r.second);
32     assert(r.first == m.begin());
33     assert(m.size() == 1);
34     assert(*r.first == 2);
35 
36     const VT v2(1);
37     r = m.insert(v2);
38     assert(r.second);
39     assert(r.first == m.begin());
40     assert(m.size() == 2);
41     assert(*r.first == 1);
42 
43     const VT v3(3);
44     r = m.insert(v3);
45     assert(r.second);
46     assert(r.first == prev(m.end()));
47     assert(m.size() == 3);
48     assert(*r.first == 3);
49 
50     r = m.insert(v3);
51     assert(!r.second);
52     assert(r.first == prev(m.end()));
53     assert(m.size() == 3);
54     assert(*r.first == 3);
55 }
56 
main()57 int main()
58 {
59     do_insert_cv_test<std::set<int> >();
60 #if TEST_STD_VER >= 11
61     {
62         typedef std::set<int, std::less<int>, min_allocator<int>> M;
63         do_insert_cv_test<M>();
64     }
65 #endif
66 }
67