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 main()21int main() 22 { 23 { 24 typedef std::set<int> M; 25 typedef std::pair<M::iterator, bool> R; 26 M m; 27 R r = m.insert(M::value_type(2)); 28 assert(r.second); 29 assert(r.first == m.begin()); 30 assert(m.size() == 1); 31 assert(*r.first == 2); 32 33 r = m.insert(M::value_type(1)); 34 assert(r.second); 35 assert(r.first == m.begin()); 36 assert(m.size() == 2); 37 assert(*r.first == 1); 38 39 r = m.insert(M::value_type(3)); 40 assert(r.second); 41 assert(r.first == prev(m.end())); 42 assert(m.size() == 3); 43 assert(*r.first == 3); 44 45 r = m.insert(M::value_type(3)); 46 assert(!r.second); 47 assert(r.first == prev(m.end())); 48 assert(m.size() == 3); 49 assert(*r.first == 3); 50 } 51 #if __cplusplus >= 201103L 52 { 53 typedef std::set<int, std::less<int>, min_allocator<int>> M; 54 typedef std::pair<M::iterator, bool> R; 55 M m; 56 R r = m.insert(M::value_type(2)); 57 assert(r.second); 58 assert(r.first == m.begin()); 59 assert(m.size() == 1); 60 assert(*r.first == 2); 61 62 r = m.insert(M::value_type(1)); 63 assert(r.second); 64 assert(r.first == m.begin()); 65 assert(m.size() == 2); 66 assert(*r.first == 1); 67 68 r = m.insert(M::value_type(3)); 69 assert(r.second); 70 assert(r.first == prev(m.end())); 71 assert(m.size() == 3); 72 assert(*r.first == 3); 73 74 r = m.insert(M::value_type(3)); 75 assert(!r.second); 76 assert(r.first == prev(m.end())); 77 assert(m.size() == 3); 78 assert(*r.first == 3); 79 } 80 #endif 81 } 82