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... Args>
17 //     iterator emplace_hint(const_iterator p, Args&&... args);
18 
19 #if _LIBCPP_DEBUG >= 1
20 #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
21 #endif
22 
23 #include <unordered_map>
24 #include <cassert>
25 
26 #include "../../../Emplaceable.h"
27 #include "min_allocator.h"
28 
main()29 int main()
30 {
31 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
32     {
33         typedef std::unordered_map<int, Emplaceable> C;
34         typedef C::iterator R;
35         C c;
36         C::const_iterator e = c.end();
37         R r = c.emplace_hint(e, std::piecewise_construct, std::forward_as_tuple(3),
38                                                           std::forward_as_tuple());
39         assert(c.size() == 1);
40         assert(r->first == 3);
41         assert(r->second == Emplaceable());
42 
43         r = c.emplace_hint(c.end(), std::pair<const int, Emplaceable>(4, Emplaceable(5, 6)));
44         assert(c.size() == 2);
45         assert(r->first == 4);
46         assert(r->second == Emplaceable(5, 6));
47 
48         r = c.emplace_hint(c.end(), std::piecewise_construct, std::forward_as_tuple(5),
49                                                        std::forward_as_tuple(6, 7));
50         assert(c.size() == 3);
51         assert(r->first == 5);
52         assert(r->second == Emplaceable(6, 7));
53     }
54 #if __cplusplus >= 201103L
55     {
56         typedef std::unordered_map<int, Emplaceable, std::hash<int>, std::equal_to<int>,
57                             min_allocator<std::pair<const int, Emplaceable>>> C;
58         typedef C::iterator R;
59         C c;
60         C::const_iterator e = c.end();
61         R r = c.emplace_hint(e, std::piecewise_construct, std::forward_as_tuple(3),
62                                                           std::forward_as_tuple());
63         assert(c.size() == 1);
64         assert(r->first == 3);
65         assert(r->second == Emplaceable());
66 
67         r = c.emplace_hint(c.end(), std::pair<const int, Emplaceable>(4, Emplaceable(5, 6)));
68         assert(c.size() == 2);
69         assert(r->first == 4);
70         assert(r->second == Emplaceable(5, 6));
71 
72         r = c.emplace_hint(c.end(), std::piecewise_construct, std::forward_as_tuple(5),
73                                                        std::forward_as_tuple(6, 7));
74         assert(c.size() == 3);
75         assert(r->first == 5);
76         assert(r->second == Emplaceable(6, 7));
77     }
78 #endif
79 #if _LIBCPP_DEBUG >= 1
80     {
81         typedef std::unordered_map<int, Emplaceable> C;
82         typedef C::iterator R;
83         typedef C::value_type P;
84         C c;
85         C c2;
86         R r = c.emplace_hint(c2.end(), std::piecewise_construct,
87                                        std::forward_as_tuple(3),
88                                        std::forward_as_tuple());
89         assert(false);
90     }
91 #endif
92 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
93 }
94