Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <set> |
| 11 | |
| 12 | // class set |
| 13 | |
| 14 | // template <class... Args> |
| 15 | // pair<iterator, bool> emplace(Args&&... args); |
| 16 | |
| 17 | #include <set> |
| 18 | #include <cassert> |
| 19 | |
| 20 | #include "../../Emplaceable.h" |
| 21 | #include "../../DefaultOnly.h" |
| 22 | |
| 23 | int main() |
| 24 | { |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 25 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 26 | { |
| 27 | typedef std::set<DefaultOnly> M; |
| 28 | typedef std::pair<M::iterator, bool> R; |
| 29 | M m; |
| 30 | assert(DefaultOnly::count == 0); |
| 31 | R r = m.emplace(); |
| 32 | assert(r.second); |
| 33 | assert(r.first == m.begin()); |
| 34 | assert(m.size() == 1); |
| 35 | assert(*m.begin() == DefaultOnly()); |
| 36 | assert(DefaultOnly::count == 1); |
| 37 | |
| 38 | r = m.emplace(); |
| 39 | assert(!r.second); |
| 40 | assert(r.first == m.begin()); |
| 41 | assert(m.size() == 1); |
| 42 | assert(*m.begin() == DefaultOnly()); |
| 43 | assert(DefaultOnly::count == 1); |
| 44 | } |
| 45 | assert(DefaultOnly::count == 0); |
| 46 | { |
| 47 | typedef std::set<Emplaceable> M; |
| 48 | typedef std::pair<M::iterator, bool> R; |
| 49 | M m; |
| 50 | R r = m.emplace(); |
| 51 | assert(r.second); |
| 52 | assert(r.first == m.begin()); |
| 53 | assert(m.size() == 1); |
| 54 | assert(*m.begin() == Emplaceable()); |
| 55 | r = m.emplace(2, 3.5); |
| 56 | assert(r.second); |
| 57 | assert(r.first == next(m.begin())); |
| 58 | assert(m.size() == 2); |
| 59 | assert(*r.first == Emplaceable(2, 3.5)); |
| 60 | r = m.emplace(2, 3.5); |
| 61 | assert(!r.second); |
| 62 | assert(r.first == next(m.begin())); |
| 63 | assert(m.size() == 2); |
| 64 | assert(*r.first == Emplaceable(2, 3.5)); |
| 65 | } |
| 66 | { |
| 67 | typedef std::set<int> M; |
| 68 | typedef std::pair<M::iterator, bool> R; |
| 69 | M m; |
| 70 | R r = m.emplace(M::value_type(2)); |
| 71 | assert(r.second); |
| 72 | assert(r.first == m.begin()); |
| 73 | assert(m.size() == 1); |
| 74 | assert(*r.first == 2); |
| 75 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 76 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 77 | } |