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

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