| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <unordered_map> |
| 10 | |
| 11 | // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, |
| 12 | // class Alloc = allocator<pair<const Key, T>>> |
| 13 | // class unordered_multimap |
| 14 | |
| 15 | // iterator insert(const value_type& x); |
| 16 | |
| 17 | #include <unordered_map> |
| 18 | #include <cassert> |
| 19 | |
| 20 | #include "test_macros.h" |
| 21 | #include "min_allocator.h" |
| 22 | |
| 23 | template <class Container> |
| 24 | void do_insert_const_lvalue_test() { |
| 25 | typedef Container C; |
| 26 | typedef typename C::iterator R; |
| 27 | typedef typename C::value_type VT; |
| 28 | C c; |
| 29 | const VT v1(3.5, 3); |
| 30 | R r = c.insert(v1); |
| 31 | assert(c.size() == 1); |
| 32 | assert(r->first == 3.5); |
| 33 | assert(r->second == 3); |
| 34 | |
| 35 | const VT v2(3.5, 4); |
| 36 | r = c.insert(v2); |
| 37 | assert(c.size() == 2); |
| 38 | assert(r->first == 3.5); |
| 39 | assert(r->second == 4); |
| 40 | |
| 41 | const VT v3(4.5, 4); |
| 42 | r = c.insert(v3); |
| 43 | assert(c.size() == 3); |
| 44 | assert(r->first == 4.5); |
| 45 | assert(r->second == 4); |
| 46 | |
| 47 | const VT v4(5.5, 4); |
| 48 | r = c.insert(v4); |
| 49 | assert(c.size() == 4); |
| 50 | assert(r->first == 5.5); |
| 51 | assert(r->second == 4); |
| 52 | } |
| 53 | |
| 54 | int main(int, char**) { |
| 55 | do_insert_const_lvalue_test<std::unordered_multimap<double, int> >(); |
| 56 | #if TEST_STD_VER >= 11 |
| 57 | { |
| 58 | typedef std::unordered_multimap<double, |
| 59 | int, |
| 60 | std::hash<double>, |
| 61 | std::equal_to<double>, |
| 62 | min_allocator<std::pair<const double, int>>> |
| 63 | C; |
| 64 | do_insert_const_lvalue_test<C>(); |
| 65 | } |
| 66 | #endif |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |