insert_hint_const_lvalue.pass.cpp (1971B)
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_set> 11 12 // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, 13 // class Alloc = allocator<Value>> 14 // class unordered_multiset 15 16 // iterator insert(const_iterator p, const value_type& x); 17 18 #if _LIBCPP_DEBUG >= 1 19 #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) 20 #endif 21 22 #include <unordered_set> 23 #include <cassert> 24 25 #include "min_allocator.h" 26 27 template<class Container> 28 void do_insert_hint_const_lvalue_test() 29 { 30 typedef Container C; 31 typedef typename C::iterator R; 32 typedef typename C::value_type VT; 33 C c; 34 typename C::const_iterator e = c.end(); 35 const VT v1(3.5); 36 R r = c.insert(e, v1); 37 assert(c.size() == 1); 38 assert(*r == 3.5); 39 40 r = c.insert(c.end(), v1); 41 assert(c.size() == 2); 42 assert(*r == 3.5); 43 44 const VT v2(4.5); 45 r = c.insert(c.end(), v2); 46 assert(c.size() == 3); 47 assert(*r == 4.5); 48 49 const VT v3(5.5); 50 r = c.insert(c.end(), v3); 51 assert(c.size() == 4); 52 assert(*r == 5.5); 53 } 54 55 int main() 56 { 57 do_insert_hint_const_lvalue_test<std::unordered_multiset<double> >(); 58 #if TEST_STD_VER >= 11 59 { 60 typedef std::unordered_multiset<double, std::hash<double>, 61 std::equal_to<double>, min_allocator<double>> C; 62 do_insert_hint_const_lvalue_test<C>(); 63 } 64 #endif 65 #if _LIBCPP_DEBUG >= 1 66 { 67 typedef std::unordered_multiset<double> C; 68 typedef C::iterator R; 69 typedef C::value_type P; 70 C c; 71 C c2; 72 C::const_iterator e = c2.end(); 73 P v(3.5); 74 R r = c.insert(e, v); 75 assert(false); 76 } 77 #endif 78 }