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_map
14
15// pair<iterator, bool> 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
23template <class Container>
24void do_insert_cv_test() {
25 typedef Container M;
26 typedef std::pair<typename M::iterator, bool> R;
27 typedef typename M::value_type VT;
28 M m;
29
30 const VT v1(2.5, 2);
31 R r = m.insert(v1);
32 assert(r.second);
33 assert(m.size() == 1);
34 assert(r.first->first == 2.5);
35 assert(r.first->second == 2);
36
37 const VT v2(2.5, 3);
38 r = m.insert(v2);
39 assert(!r.second);
40 assert(m.size() == 1);
41 assert(r.first->first == 2.5);
42 assert(r.first->second == 2);
43
44 const VT v3(1.5, 1);
45 r = m.insert(v3);
46 assert(r.second);
47 assert(m.size() == 2);
48 assert(r.first->first == 1.5);
49 assert(r.first->second == 1);
50
51 const VT v4(3.5, 3);
52 r = m.insert(v4);
53 assert(r.second);
54 assert(m.size() == 3);
55 assert(r.first->first == 3.5);
56 assert(r.first->second == 3);
57
58 const VT v5(3.5, 4);
59 r = m.insert(v5);
60 assert(!r.second);
61 assert(m.size() == 3);
62 assert(r.first->first == 3.5);
63 assert(r.first->second == 3);
64}
65
66int main(int, char**) {
67 {
68 typedef std::unordered_map<double, int> M;
69 do_insert_cv_test<M>();
70 }
71#if TEST_STD_VER >= 11
72 {
73 typedef std::unordered_map<double,
74 int,
75 std::hash<double>,
76 std::equal_to<double>,
77 min_allocator<std::pair<const double, int>>>
78 M;
79 do_insert_cv_test<M>();
80 }
81#endif
82
83 return 0;
84}
85

source code of libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_const_lvalue.pass.cpp