[libc++] Fix hash_multi{map,set}::insert (#149290)
(cherry picked from commit be3d614cc13f016b16634e18e10caed508d183d2)
This commit is contained in:
parent
3db29aaee5
commit
564ed8e064
@ -744,7 +744,7 @@ public:
|
|||||||
_LIBCPP_HIDE_FROM_ABI const_iterator begin() const { return __table_.begin(); }
|
_LIBCPP_HIDE_FROM_ABI const_iterator begin() const { return __table_.begin(); }
|
||||||
_LIBCPP_HIDE_FROM_ABI const_iterator end() const { return __table_.end(); }
|
_LIBCPP_HIDE_FROM_ABI const_iterator end() const { return __table_.end(); }
|
||||||
|
|
||||||
_LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return __table_.__emplace_unique(__x); }
|
_LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return __table_.__emplace_multi(__x); }
|
||||||
_LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, const value_type& __x) { return insert(__x); }
|
_LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, const value_type& __x) { return insert(__x); }
|
||||||
template <class _InputIterator>
|
template <class _InputIterator>
|
||||||
_LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator __last);
|
_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>
|
|||||||
template <class _InputIterator>
|
template <class _InputIterator>
|
||||||
inline void hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, _InputIterator __last) {
|
inline void hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, _InputIterator __last) {
|
||||||
for (; __first != __last; ++__first)
|
for (; __first != __last; ++__first)
|
||||||
__table_.__emplace_unique(*__first);
|
__table_.__emplace_multi(*__first);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
|
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
|
||||||
|
@ -458,7 +458,7 @@ public:
|
|||||||
_LIBCPP_HIDE_FROM_ABI const_iterator begin() const { return __table_.begin(); }
|
_LIBCPP_HIDE_FROM_ABI const_iterator begin() const { return __table_.begin(); }
|
||||||
_LIBCPP_HIDE_FROM_ABI const_iterator end() const { return __table_.end(); }
|
_LIBCPP_HIDE_FROM_ABI const_iterator end() const { return __table_.end(); }
|
||||||
|
|
||||||
_LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return __table_.__emplace_unique(__x); }
|
_LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return __table_.__emplace_multi(__x); }
|
||||||
_LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, const value_type& __x) { return insert(__x); }
|
_LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, const value_type& __x) { return insert(__x); }
|
||||||
template <class _InputIterator>
|
template <class _InputIterator>
|
||||||
_LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator __last);
|
_LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator __last);
|
||||||
@ -543,7 +543,7 @@ template <class _Value, class _Hash, class _Pred, class _Alloc>
|
|||||||
template <class _InputIterator>
|
template <class _InputIterator>
|
||||||
inline void hash_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, _InputIterator __last) {
|
inline void hash_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, _InputIterator __last) {
|
||||||
for (; __first != __last; ++__first)
|
for (; __first != __last; ++__first)
|
||||||
__table_.__emplace_unique(*__first);
|
__table_.__emplace_multi(*__first);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class _Value, class _Hash, class _Pred, class _Alloc>
|
template <class _Value, class _Hash, class _Pred, class _Alloc>
|
||||||
|
35
libcxx/test/extensions/gnu/hash_multimap/insert.pass.cpp
Normal file
35
libcxx/test/extensions/gnu/hash_multimap/insert.pass.cpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||||
|
// See https://llvm.org/LICENSE.txt for license information.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// ADDITIONAL_COMPILE_FLAGS: -Wno-deprecated
|
||||||
|
|
||||||
|
// hash_multimap::insert
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <ext/hash_map>
|
||||||
|
|
||||||
|
int main(int, char**) {
|
||||||
|
__gnu_cxx::hash_multimap<int, int> map;
|
||||||
|
|
||||||
|
map.insert(std::make_pair(1, 1));
|
||||||
|
map.insert(std::make_pair(1, 1));
|
||||||
|
|
||||||
|
assert(map.size() == 2);
|
||||||
|
assert(map.equal_range(1).first == map.begin());
|
||||||
|
assert(map.equal_range(1).second == map.end());
|
||||||
|
|
||||||
|
std::pair<int, int> arr[] = {std::make_pair(1, 1), std::make_pair(1, 1)};
|
||||||
|
|
||||||
|
map.insert(arr, arr + 2);
|
||||||
|
|
||||||
|
assert(map.size() == 4);
|
||||||
|
assert(map.equal_range(1).first == map.begin());
|
||||||
|
assert(map.equal_range(1).second == map.end());
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
35
libcxx/test/extensions/gnu/hash_multiset/insert.pass.cpp
Normal file
35
libcxx/test/extensions/gnu/hash_multiset/insert.pass.cpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||||
|
// See https://llvm.org/LICENSE.txt for license information.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// ADDITIONAL_COMPILE_FLAGS: -Wno-deprecated
|
||||||
|
|
||||||
|
// hash_multimap::insert
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <ext/hash_set>
|
||||||
|
|
||||||
|
int main(int, char**) {
|
||||||
|
__gnu_cxx::hash_multiset<int> map;
|
||||||
|
|
||||||
|
map.insert(1);
|
||||||
|
map.insert(1);
|
||||||
|
|
||||||
|
assert(map.size() == 2);
|
||||||
|
assert(map.equal_range(1).first == map.begin());
|
||||||
|
assert(map.equal_range(1).second == map.end());
|
||||||
|
|
||||||
|
int arr[] = {1, 1};
|
||||||
|
|
||||||
|
map.insert(arr, arr + 2);
|
||||||
|
|
||||||
|
assert(map.size() == 4);
|
||||||
|
assert(map.equal_range(1).first == map.begin());
|
||||||
|
assert(map.equal_range(1).second == map.end());
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user