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 | // <map> |
| 11 | |
| 12 | // class map |
| 13 | |
| 14 | // template <class... Args> |
| 15 | // pair<iterator, bool> emplace(Args&&... args); |
| 16 | |
| 17 | #include <map> |
| 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::map<int, 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()->first == 0); |
| 36 | assert(m.begin()->second == DefaultOnly()); |
| 37 | assert(DefaultOnly::count == 1); |
| 38 | r = m.emplace(1); |
| 39 | assert(r.second); |
| 40 | assert(r.first == next(m.begin())); |
| 41 | assert(m.size() == 2); |
| 42 | assert(next(m.begin())->first == 1); |
| 43 | assert(next(m.begin())->second == DefaultOnly()); |
| 44 | assert(DefaultOnly::count == 2); |
| 45 | r = m.emplace(1); |
| 46 | assert(!r.second); |
| 47 | assert(r.first == next(m.begin())); |
| 48 | assert(m.size() == 2); |
| 49 | assert(next(m.begin())->first == 1); |
| 50 | assert(next(m.begin())->second == DefaultOnly()); |
| 51 | assert(DefaultOnly::count == 2); |
| 52 | } |
| 53 | assert(DefaultOnly::count == 0); |
| 54 | { |
| 55 | typedef std::map<int, Emplaceable> M; |
| 56 | typedef std::pair<M::iterator, bool> R; |
| 57 | M m; |
| 58 | R r = m.emplace(2); |
| 59 | assert(r.second); |
| 60 | assert(r.first == m.begin()); |
| 61 | assert(m.size() == 1); |
| 62 | assert(m.begin()->first == 2); |
| 63 | assert(m.begin()->second == Emplaceable()); |
| 64 | r = m.emplace(1, 2, 3.5); |
| 65 | assert(r.second); |
| 66 | assert(r.first == m.begin()); |
| 67 | assert(m.size() == 2); |
| 68 | assert(m.begin()->first == 1); |
| 69 | assert(m.begin()->second == Emplaceable(2, 3.5)); |
| 70 | r = m.emplace(1, 2, 3.5); |
| 71 | assert(!r.second); |
| 72 | assert(r.first == m.begin()); |
| 73 | assert(m.size() == 2); |
| 74 | assert(m.begin()->first == 1); |
| 75 | assert(m.begin()->second == Emplaceable(2, 3.5)); |
| 76 | } |
| 77 | { |
| 78 | typedef std::map<int, double> M; |
| 79 | typedef std::pair<M::iterator, bool> R; |
| 80 | M m; |
| 81 | R r = m.emplace(M::value_type(2, 3.5)); |
| 82 | assert(r.second); |
| 83 | assert(r.first == m.begin()); |
| 84 | assert(m.size() == 1); |
| 85 | assert(m.begin()->first == 2); |
| 86 | assert(m.begin()->second == 3.5); |
| 87 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 88 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 89 | } |