insert_rvalue.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// <unordered_map> 11 12// template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, 13// class Alloc = allocator<pair<const Key, T>>> 14// class unordered_map 15 16// template <class P, 17// class = typename enable_if<is_convertible<P, value_type>::value>::type> 18// pair<iterator, bool> insert(P&& x); 19 20#include <unordered_map> 21#include <cassert> 22 23#include "../../../MoveOnly.h" 24 25int main() 26{ 27 { 28 typedef std::unordered_map<double, int> C; 29 typedef std::pair<C::iterator, bool> R; 30 typedef std::pair<double, short> P; 31 C c; 32 R r = c.insert(P(3.5, 3)); 33 assert(r.second); 34 assert(c.size() == 1); 35 assert(r.first->first == 3.5); 36 assert(r.first->second == 3); 37 38 r = c.insert(P(3.5, 4)); 39 assert(!r.second); 40 assert(c.size() == 1); 41 assert(r.first->first == 3.5); 42 assert(r.first->second == 3); 43 44 r = c.insert(P(4.5, 4)); 45 assert(r.second); 46 assert(c.size() == 2); 47 assert(r.first->first == 4.5); 48 assert(r.first->second == 4); 49 50 r = c.insert(P(5.5, 4)); 51 assert(r.second); 52 assert(c.size() == 3); 53 assert(r.first->first == 5.5); 54 assert(r.first->second == 4); 55 } 56#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 57 { 58 typedef std::unordered_map<MoveOnly, MoveOnly> C; 59 typedef std::pair<C::iterator, bool> R; 60 typedef std::pair<MoveOnly, MoveOnly> P; 61 C c; 62 R r = c.insert(P(3, 3)); 63 assert(r.second); 64 assert(c.size() == 1); 65 assert(r.first->first == 3); 66 assert(r.first->second == 3); 67 68 r = c.insert(P(3, 4)); 69 assert(!r.second); 70 assert(c.size() == 1); 71 assert(r.first->first == 3); 72 assert(r.first->second == 3); 73 74 r = c.insert(P(4, 4)); 75 assert(r.second); 76 assert(c.size() == 2); 77 assert(r.first->first == 4); 78 assert(r.first->second == 4); 79 80 r = c.insert(P(5, 4)); 81 assert(r.second); 82 assert(c.size() == 3); 83 assert(r.first->first == 5); 84 assert(r.first->second == 4); 85 } 86#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 87} 88