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 // template <class... Args> 17 // pair<iterator, bool> emplace(Args&&... args); 18 19 #include <set> 20 #include <cassert> 21 22 #include "../../Emplaceable.h" 23 #include "DefaultOnly.h" 24 #include "min_allocator.h" 25 26 int main() 27 { 28 { 29 typedef std::set<DefaultOnly> M; 30 typedef std::pair<M::iterator, bool> R; 31 M m; 32 assert(DefaultOnly::count == 0); 33 R r = m.emplace(); 34 assert(r.second); 35 assert(r.first == m.begin()); 36 assert(m.size() == 1); 37 assert(*m.begin() == DefaultOnly()); 38 assert(DefaultOnly::count == 1); 39 40 r = m.emplace(); 41 assert(!r.second); 42 assert(r.first == m.begin()); 43 assert(m.size() == 1); 44 assert(*m.begin() == DefaultOnly()); 45 assert(DefaultOnly::count == 1); 46 } 47 assert(DefaultOnly::count == 0); 48 { 49 typedef std::set<Emplaceable> M; 50 typedef std::pair<M::iterator, bool> R; 51 M m; 52 R r = m.emplace(); 53 assert(r.second); 54 assert(r.first == m.begin()); 55 assert(m.size() == 1); 56 assert(*m.begin() == Emplaceable()); 57 r = m.emplace(2, 3.5); 58 assert(r.second); 59 assert(r.first == next(m.begin())); 60 assert(m.size() == 2); 61 assert(*r.first == Emplaceable(2, 3.5)); 62 r = m.emplace(2, 3.5); 63 assert(!r.second); 64 assert(r.first == next(m.begin())); 65 assert(m.size() == 2); 66 assert(*r.first == Emplaceable(2, 3.5)); 67 } 68 { 69 typedef std::set<int> M; 70 typedef std::pair<M::iterator, bool> R; 71 M m; 72 R r = m.emplace(M::value_type(2)); 73 assert(r.second); 74 assert(r.first == m.begin()); 75 assert(m.size() == 1); 76 assert(*r.first == 2); 77 } 78 { 79 typedef std::set<int, std::less<int>, min_allocator<int>> M; 80 typedef std::pair<M::iterator, bool> R; 81 M m; 82 R r = m.emplace(M::value_type(2)); 83 assert(r.second); 84 assert(r.first == m.begin()); 85 assert(m.size() == 1); 86 assert(*r.first == 2); 87 } 88 } 89