emplace_hint.pass.cpp revision b64f8b07c104c6cc986570ac8ee0ed16a9f23976
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// <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 23int main() 24{ 25#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 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 } 81#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 82} 83