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 | // iterator emplace_hint(const_iterator position, 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 M::iterator R; |
| 29 | M m; |
| 30 | assert(DefaultOnly::count == 0); |
| 31 | R r = m.emplace_hint(m.end()); |
| 32 | assert(r == m.begin()); |
| 33 | assert(m.size() == 1); |
| 34 | assert(m.begin()->first == 0); |
| 35 | assert(m.begin()->second == DefaultOnly()); |
| 36 | assert(DefaultOnly::count == 1); |
| 37 | r = m.emplace_hint(m.end(), 1); |
| 38 | assert(r == next(m.begin())); |
| 39 | assert(m.size() == 2); |
| 40 | assert(next(m.begin())->first == 1); |
| 41 | assert(next(m.begin())->second == DefaultOnly()); |
| 42 | assert(DefaultOnly::count == 2); |
| 43 | r = m.emplace_hint(m.end(), 1); |
| 44 | assert(r == next(m.begin())); |
| 45 | assert(m.size() == 2); |
| 46 | assert(next(m.begin())->first == 1); |
| 47 | assert(next(m.begin())->second == DefaultOnly()); |
| 48 | assert(DefaultOnly::count == 2); |
| 49 | } |
| 50 | assert(DefaultOnly::count == 0); |
| 51 | { |
| 52 | typedef std::map<int, Emplaceable> M; |
| 53 | typedef M::iterator R; |
| 54 | M m; |
| 55 | R r = m.emplace_hint(m.end(), 2); |
| 56 | assert(r == m.begin()); |
| 57 | assert(m.size() == 1); |
| 58 | assert(m.begin()->first == 2); |
| 59 | assert(m.begin()->second == Emplaceable()); |
| 60 | r = m.emplace_hint(m.end(), 1, 2, 3.5); |
| 61 | assert(r == m.begin()); |
| 62 | assert(m.size() == 2); |
| 63 | assert(m.begin()->first == 1); |
| 64 | assert(m.begin()->second == Emplaceable(2, 3.5)); |
| 65 | r = m.emplace_hint(m.end(), 1, 2, 3.5); |
| 66 | assert(r == m.begin()); |
| 67 | assert(m.size() == 2); |
| 68 | assert(m.begin()->first == 1); |
| 69 | assert(m.begin()->second == Emplaceable(2, 3.5)); |
| 70 | } |
| 71 | { |
| 72 | typedef std::map<int, double> M; |
| 73 | typedef M::iterator R; |
| 74 | M m; |
| 75 | R r = m.emplace_hint(m.end(), M::value_type(2, 3.5)); |
| 76 | assert(r == m.begin()); |
| 77 | assert(m.size() == 1); |
| 78 | assert(m.begin()->first == 2); |
| 79 | assert(m.begin()->second == 3.5); |
| 80 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 81 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 82 | } |