Skip to content

Commit be3d614

Browse files
authored
[libc++] Fix hash_multi{map,set}::insert (#149290)
1 parent 422a250 commit be3d614

File tree

4 files changed

+74
-4
lines changed

4 files changed

+74
-4
lines changed

libcxx/include/ext/hash_map

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ public:
744744
_LIBCPP_HIDE_FROM_ABI const_iterator begin() const { return __table_.begin(); }
745745
_LIBCPP_HIDE_FROM_ABI const_iterator end() const { return __table_.end(); }
746746

747-
_LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return __table_.__emplace_unique(__x); }
747+
_LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return __table_.__emplace_multi(__x); }
748748
_LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, const value_type& __x) { return insert(__x); }
749749
template <class _InputIterator>
750750
_LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator __last);
@@ -831,7 +831,7 @@ template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
831831
template <class _InputIterator>
832832
inline void hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, _InputIterator __last) {
833833
for (; __first != __last; ++__first)
834-
__table_.__emplace_unique(*__first);
834+
__table_.__emplace_multi(*__first);
835835
}
836836

837837
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>

libcxx/include/ext/hash_set

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ public:
458458
_LIBCPP_HIDE_FROM_ABI const_iterator begin() const { return __table_.begin(); }
459459
_LIBCPP_HIDE_FROM_ABI const_iterator end() const { return __table_.end(); }
460460

461-
_LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return __table_.__emplace_unique(__x); }
461+
_LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return __table_.__emplace_multi(__x); }
462462
_LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, const value_type& __x) { return insert(__x); }
463463
template <class _InputIterator>
464464
_LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator __last);
@@ -543,7 +543,7 @@ template <class _Value, class _Hash, class _Pred, class _Alloc>
543543
template <class _InputIterator>
544544
inline void hash_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, _InputIterator __last) {
545545
for (; __first != __last; ++__first)
546-
__table_.__emplace_unique(*__first);
546+
__table_.__emplace_multi(*__first);
547547
}
548548

549549
template <class _Value, class _Hash, class _Pred, class _Alloc>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
// ADDITIONAL_COMPILE_FLAGS: -Wno-deprecated
10+
11+
// hash_multimap::insert
12+
13+
#include <cassert>
14+
#include <ext/hash_map>
15+
16+
int main(int, char**) {
17+
__gnu_cxx::hash_multimap<int, int> map;
18+
19+
map.insert(std::make_pair(1, 1));
20+
map.insert(std::make_pair(1, 1));
21+
22+
assert(map.size() == 2);
23+
assert(map.equal_range(1).first == map.begin());
24+
assert(map.equal_range(1).second == map.end());
25+
26+
std::pair<int, int> arr[] = {std::make_pair(1, 1), std::make_pair(1, 1)};
27+
28+
map.insert(arr, arr + 2);
29+
30+
assert(map.size() == 4);
31+
assert(map.equal_range(1).first == map.begin());
32+
assert(map.equal_range(1).second == map.end());
33+
34+
return 0;
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
// ADDITIONAL_COMPILE_FLAGS: -Wno-deprecated
10+
11+
// hash_multimap::insert
12+
13+
#include <cassert>
14+
#include <ext/hash_set>
15+
16+
int main(int, char**) {
17+
__gnu_cxx::hash_multiset<int> map;
18+
19+
map.insert(1);
20+
map.insert(1);
21+
22+
assert(map.size() == 2);
23+
assert(map.equal_range(1).first == map.begin());
24+
assert(map.equal_range(1).second == map.end());
25+
26+
int arr[] = {1, 1};
27+
28+
map.insert(arr, arr + 2);
29+
30+
assert(map.size() == 4);
31+
assert(map.equal_range(1).first == map.begin());
32+
assert(map.equal_range(1).second == map.end());
33+
34+
return 0;
35+
}

0 commit comments

Comments
 (0)