insert_const_lvalue.pass.cpp revision 061d0cc4db18d17bf01ed14c5db0be098205bd47
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// pair<iterator, bool> insert(const value_type& x); 17 18#include <unordered_map> 19#include <cassert> 20 21#include "min_allocator.h" 22 23int main() 24{ 25 { 26 typedef std::unordered_map<double, int> C; 27 typedef std::pair<C::iterator, bool> R; 28 typedef C::value_type P; 29 C c; 30 R r = c.insert(P(3.5, 3)); 31 assert(r.second); 32 assert(c.size() == 1); 33 assert(r.first->first == 3.5); 34 assert(r.first->second == 3); 35 36 r = c.insert(P(3.5, 4)); 37 assert(!r.second); 38 assert(c.size() == 1); 39 assert(r.first->first == 3.5); 40 assert(r.first->second == 3); 41 42 r = c.insert(P(4.5, 4)); 43 assert(r.second); 44 assert(c.size() == 2); 45 assert(r.first->first == 4.5); 46 assert(r.first->second == 4); 47 48 r = c.insert(P(5.5, 4)); 49 assert(r.second); 50 assert(c.size() == 3); 51 assert(r.first->first == 5.5); 52 assert(r.first->second == 4); 53 } 54#if __cplusplus >= 201103L 55 { 56 typedef std::unordered_map<double, int, std::hash<double>, std::equal_to<double>, 57 min_allocator<std::pair<const double, int>>> C; 58 typedef std::pair<C::iterator, bool> R; 59 typedef C::value_type P; 60 C c; 61 R r = c.insert(P(3.5, 3)); 62 assert(r.second); 63 assert(c.size() == 1); 64 assert(r.first->first == 3.5); 65 assert(r.first->second == 3); 66 67 r = c.insert(P(3.5, 4)); 68 assert(!r.second); 69 assert(c.size() == 1); 70 assert(r.first->first == 3.5); 71 assert(r.first->second == 3); 72 73 r = c.insert(P(4.5, 4)); 74 assert(r.second); 75 assert(c.size() == 2); 76 assert(r.first->first == 4.5); 77 assert(r.first->second == 4); 78 79 r = c.insert(P(5.5, 4)); 80 assert(r.second); 81 assert(c.size() == 3); 82 assert(r.first->first == 5.5); 83 assert(r.first->second == 4); 84 } 85#endif 86} 87