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 // UNSUPPORTED: c++98, c++03 11 12 // <set> 13 14 // class set 15 16 // pair<iterator, bool> insert(value_type&& v); 17 18 #include <set> 19 #include <cassert> 20 21 #include "MoveOnly.h" 22 #include "min_allocator.h" 23 main()24int main() 25 { 26 { 27 typedef std::set<MoveOnly> M; 28 typedef std::pair<M::iterator, bool> R; 29 M m; 30 R r = m.insert(M::value_type(2)); 31 assert(r.second); 32 assert(r.first == m.begin()); 33 assert(m.size() == 1); 34 assert(*r.first == 2); 35 36 r = m.insert(M::value_type(1)); 37 assert(r.second); 38 assert(r.first == m.begin()); 39 assert(m.size() == 2); 40 assert(*r.first == 1); 41 42 r = m.insert(M::value_type(3)); 43 assert(r.second); 44 assert(r.first == prev(m.end())); 45 assert(m.size() == 3); 46 assert(*r.first == 3); 47 48 r = m.insert(M::value_type(3)); 49 assert(!r.second); 50 assert(r.first == prev(m.end())); 51 assert(m.size() == 3); 52 assert(*r.first == 3); 53 } 54 { 55 typedef std::set<MoveOnly, std::less<MoveOnly>, min_allocator<MoveOnly>> M; 56 typedef std::pair<M::iterator, bool> R; 57 M m; 58 R r = m.insert(M::value_type(2)); 59 assert(r.second); 60 assert(r.first == m.begin()); 61 assert(m.size() == 1); 62 assert(*r.first == 2); 63 64 r = m.insert(M::value_type(1)); 65 assert(r.second); 66 assert(r.first == m.begin()); 67 assert(m.size() == 2); 68 assert(*r.first == 1); 69 70 r = m.insert(M::value_type(3)); 71 assert(r.second); 72 assert(r.first == prev(m.end())); 73 assert(m.size() == 3); 74 assert(*r.first == 3); 75 76 r = m.insert(M::value_type(3)); 77 assert(!r.second); 78 assert(r.first == prev(m.end())); 79 assert(m.size() == 3); 80 assert(*r.first == 3); 81 } 82 } 83