emplace.pass.cpp revision 1ae14a374d5e15c60c6d3ae4adbcdf57c5e3a401
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// <unordered_map> 13 14// template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, 15// class Alloc = allocator<pair<const Key, T>>> 16// class unordered_map 17 18// template <class... Args> 19// pair<iterator, bool> emplace(Args&&... args); 20 21#include <unordered_map> 22#include <cassert> 23 24#include "../../../Emplaceable.h" 25#include "min_allocator.h" 26 27int main() 28{ 29 { 30 typedef std::unordered_map<int, Emplaceable> C; 31 typedef std::pair<C::iterator, bool> R; 32 C c; 33 R r = c.emplace(std::piecewise_construct, std::forward_as_tuple(3), 34 std::forward_as_tuple()); 35 assert(r.second); 36 assert(c.size() == 1); 37 assert(r.first->first == 3); 38 assert(r.first->second == Emplaceable()); 39 40 r = c.emplace(std::pair<const int, Emplaceable>(4, Emplaceable(5, 6))); 41 assert(r.second); 42 assert(c.size() == 2); 43 assert(r.first->first == 4); 44 assert(r.first->second == Emplaceable(5, 6)); 45 46 r = c.emplace(std::piecewise_construct, std::forward_as_tuple(5), 47 std::forward_as_tuple(6, 7)); 48 assert(r.second); 49 assert(c.size() == 3); 50 assert(r.first->first == 5); 51 assert(r.first->second == Emplaceable(6, 7)); 52 } 53 { 54 typedef std::unordered_map<int, Emplaceable, std::hash<int>, std::equal_to<int>, 55 min_allocator<std::pair<const int, Emplaceable>>> C; 56 typedef std::pair<C::iterator, bool> R; 57 C c; 58 R r = c.emplace(std::piecewise_construct, std::forward_as_tuple(3), 59 std::forward_as_tuple()); 60 assert(r.second); 61 assert(c.size() == 1); 62 assert(r.first->first == 3); 63 assert(r.first->second == Emplaceable()); 64 65 r = c.emplace(std::pair<const int, Emplaceable>(4, Emplaceable(5, 6))); 66 assert(r.second); 67 assert(c.size() == 2); 68 assert(r.first->first == 4); 69 assert(r.first->second == Emplaceable(5, 6)); 70 71 r = c.emplace(std::piecewise_construct, std::forward_as_tuple(5), 72 std::forward_as_tuple(6, 7)); 73 assert(r.second); 74 assert(c.size() == 3); 75 assert(r.first->first == 5); 76 assert(r.first->second == Emplaceable(6, 7)); 77 } 78} 79