insert_hint_rvalue.pass.cpp revision b64f8b07c104c6cc986570ac8ee0ed16a9f23976
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 P,
17//           class = typename enable_if<is_convertible<P, value_type>::value>::type>
18//     iterator insert(const_iterator p, P&& x);
19
20#include <unordered_map>
21#include <cassert>
22
23#include "../../../MoveOnly.h"
24
25int main()
26{
27    {
28        typedef std::unordered_map<double, int> C;
29        typedef C::iterator R;
30        typedef std::pair<double, short> P;
31        C c;
32        C::const_iterator e = c.end();
33        R r = c.insert(e, P(3.5, 3));
34        assert(c.size() == 1);
35        assert(r->first == 3.5);
36        assert(r->second == 3);
37
38        r = c.insert(e, P(3.5, 4));
39        assert(c.size() == 1);
40        assert(r->first == 3.5);
41        assert(r->second == 3);
42
43        r = c.insert(e, P(4.5, 4));
44        assert(c.size() == 2);
45        assert(r->first == 4.5);
46        assert(r->second == 4);
47
48        r = c.insert(e, P(5.5, 4));
49        assert(c.size() == 3);
50        assert(r->first == 5.5);
51        assert(r->second == 4);
52    }
53#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
54    {
55        typedef std::unordered_map<MoveOnly, MoveOnly> C;
56        typedef C::iterator R;
57        typedef std::pair<MoveOnly, MoveOnly> P;
58        C c;
59        C::const_iterator e = c.end();
60        R r = c.insert(e, P(3, 3));
61        assert(c.size() == 1);
62        assert(r->first == 3);
63        assert(r->second == 3);
64
65        r = c.insert(e, P(3, 4));
66        assert(c.size() == 1);
67        assert(r->first == 3);
68        assert(r->second == 3);
69
70        r = c.insert(e, P(4, 4));
71        assert(c.size() == 2);
72        assert(r->first == 4);
73        assert(r->second == 4);
74
75        r = c.insert(e, P(5, 4));
76        assert(c.size() == 3);
77        assert(r->first == 5);
78        assert(r->second == 4);
79    }
80#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
81}
82