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// 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_map>
23#include <cassert>
24
25#include "min_allocator.h"
26
27int main()
28{
29    {
30        typedef std::unordered_map<double, int> C;
31        typedef C::iterator R;
32        typedef C::value_type P;
33        C c;
34        C::const_iterator e = c.end();
35        R r = c.insert(e, P(3.5, 3));
36        assert(c.size() == 1);
37        assert(r->first == 3.5);
38        assert(r->second == 3);
39
40        r = c.insert(c.end(), P(3.5, 4));
41        assert(c.size() == 1);
42        assert(r->first == 3.5);
43        assert(r->second == 3);
44
45        r = c.insert(c.end(), P(4.5, 4));
46        assert(c.size() == 2);
47        assert(r->first == 4.5);
48        assert(r->second == 4);
49
50        r = c.insert(c.end(), P(5.5, 4));
51        assert(c.size() == 3);
52        assert(r->first == 5.5);
53        assert(r->second == 4);
54    }
55#if __cplusplus >= 201103L
56    {
57        typedef std::unordered_map<double, int, std::hash<double>, std::equal_to<double>,
58                            min_allocator<std::pair<const double, int>>> C;
59        typedef C::iterator R;
60        typedef C::value_type P;
61        C c;
62        C::const_iterator e = c.end();
63        R r = c.insert(e, P(3.5, 3));
64        assert(c.size() == 1);
65        assert(r->first == 3.5);
66        assert(r->second == 3);
67
68        r = c.insert(c.end(), P(3.5, 4));
69        assert(c.size() == 1);
70        assert(r->first == 3.5);
71        assert(r->second == 3);
72
73        r = c.insert(c.end(), P(4.5, 4));
74        assert(c.size() == 2);
75        assert(r->first == 4.5);
76        assert(r->second == 4);
77
78        r = c.insert(c.end(), P(5.5, 4));
79        assert(c.size() == 3);
80        assert(r->first == 5.5);
81        assert(r->second == 4);
82    }
83#endif
84#if _LIBCPP_DEBUG >= 1
85    {
86        typedef std::unordered_map<double, int> C;
87        typedef C::iterator R;
88        typedef C::value_type P;
89        C c;
90        C c2;
91        C::const_iterator e = c2.end();
92        P v(3.5, 3);
93        R r = c.insert(e, v);
94        assert(false);
95    }
96#endif
97}
98