diff --git a/libcxx/include/unordered_map b/libcxx/include/unordered_map --- a/libcxx/include/unordered_map +++ b/libcxx/include/unordered_map @@ -1373,7 +1373,7 @@ #if _LIBCPP_STD_VER > 17 template ::value && __is_transparent::value>* = nullptr> _LIBCPP_INLINE_VISIBILITY - size_type count(const _K2& __k) const {return __table_.__count_unique(__k);} + size_type count(const _K2& __k) const {return __table_.__count_multi(__k);} #endif // _LIBCPP_STD_VER > 17 #if _LIBCPP_STD_VER > 17 @@ -1395,11 +1395,11 @@ template ::value && __is_transparent::value>* = nullptr> _LIBCPP_INLINE_VISIBILITY pair equal_range(const _K2& __k) - {return __table_.__equal_range_unique(__k);} + {return __table_.__equal_range_multi(__k);} template ::value && __is_transparent::value>* = nullptr> _LIBCPP_INLINE_VISIBILITY pair equal_range(const _K2& __k) const - {return __table_.__equal_range_unique(__k);} + {return __table_.__equal_range_multi(__k);} #endif // _LIBCPP_STD_VER > 17 mapped_type& operator[](const key_type& __k); diff --git a/libcxx/include/unordered_set b/libcxx/include/unordered_set --- a/libcxx/include/unordered_set +++ b/libcxx/include/unordered_set @@ -720,7 +720,7 @@ #if _LIBCPP_STD_VER > 17 template ::value && __is_transparent::value>* = nullptr> _LIBCPP_INLINE_VISIBILITY - size_type count(const _K2& __k) const {return __table_.__count_unique(__k);} + size_type count(const _K2& __k) const {return __table_.__count_multi(__k);} #endif // _LIBCPP_STD_VER > 17 #if _LIBCPP_STD_VER > 17 @@ -742,11 +742,11 @@ template ::value && __is_transparent::value>* = nullptr> _LIBCPP_INLINE_VISIBILITY pair equal_range(const _K2& __k) - {return __table_.__equal_range_unique(__k);} + {return __table_.__equal_range_multi(__k);} template ::value && __is_transparent::value>* = nullptr> _LIBCPP_INLINE_VISIBILITY pair equal_range(const _K2& __k) const - {return __table_.__equal_range_unique(__k);} + {return __table_.__equal_range_multi(__k);} #endif // _LIBCPP_STD_VER > 17 _LIBCPP_INLINE_VISIBILITY diff --git a/libcxx/test/std/containers/associative/map/map.ops/count_transparent.pass.cpp b/libcxx/test/std/containers/associative/map/map.ops/count_transparent.pass.cpp --- a/libcxx/test/std/containers/associative/map/map.ops/count_transparent.pass.cpp +++ b/libcxx/test/std/containers/associative/map/map.ops/count_transparent.pass.cpp @@ -15,8 +15,8 @@ // template // size_type count(const K& x) const; // C++14 -#include #include +#include #include struct Comp { @@ -37,10 +37,11 @@ }; int main(int, char**) { - std::map, int, Comp> s{ - {{2, 1}, 1}, {{1, 2}, 2}, {{1, 3}, 3}, {{1, 4}, 4}, {{2, 2}, 5}}; + std::map, int, Comp> m = { + {{2, 1}, 1}, {{1, 2}, 2}, {{1, 3}, 3}, {{1, 4}, 4}, {{2, 2}, 5} + }; - auto cnt = s.count(1); + auto cnt = m.count(1); assert(cnt == 3); return 0; diff --git a/libcxx/test/std/containers/associative/map/map.ops/equal_range_transparent.pass.cpp b/libcxx/test/std/containers/associative/map/map.ops/equal_range_transparent.pass.cpp --- a/libcxx/test/std/containers/associative/map/map.ops/equal_range_transparent.pass.cpp +++ b/libcxx/test/std/containers/associative/map/map.ops/equal_range_transparent.pass.cpp @@ -13,13 +13,12 @@ // class map // template -// pair equal_range(const K& x); // C++14 +// pair equal_range(const K& x); // C++14 // template -// pair equal_range(const K& x) const; -// // C++14 +// pair equal_range(const K& x) const; // C++14 -#include #include +#include #include struct Comp { @@ -40,18 +39,23 @@ }; int main(int, char**) { - std::map, int, Comp> s{ - {{2, 1}, 1}, {{1, 2}, 2}, {{1, 3}, 3}, {{1, 4}, 4}, {{2, 2}, 5}}; + std::map, int, Comp> m = { + {{2, 1}, 1}, {{1, 2}, 2}, {{1, 3}, 3}, {{1, 4}, 4}, {{2, 2}, 5} + }; - auto er = s.equal_range(1); + auto er = m.equal_range(1); long nels = 0; for (auto it = er.first; it != er.second; it++) { assert(it->first.first == 1); nels++; } - assert(nels == 3); + const auto& cm = m; + auto cer = cm.equal_range(1); + assert(cer.first == er.first); + assert(cer.second == er.second); + return 0; } diff --git a/libcxx/test/std/containers/associative/set/count_transparent.pass.cpp b/libcxx/test/std/containers/associative/set/count_transparent.pass.cpp --- a/libcxx/test/std/containers/associative/set/count_transparent.pass.cpp +++ b/libcxx/test/std/containers/associative/set/count_transparent.pass.cpp @@ -15,8 +15,8 @@ // template // size_type count(const K& x) const; // C++14 -#include #include +#include #include struct Comp { diff --git a/libcxx/test/std/containers/associative/set/equal_range_transparent.pass.cpp b/libcxx/test/std/containers/associative/set/equal_range_transparent.pass.cpp --- a/libcxx/test/std/containers/associative/set/equal_range_transparent.pass.cpp +++ b/libcxx/test/std/containers/associative/set/equal_range_transparent.pass.cpp @@ -19,8 +19,8 @@ // pair equal_range(const K& x) const; // // C++14 -#include #include +#include #include struct Comp { @@ -50,8 +50,12 @@ assert(it->first == 1); nels++; } - assert(nels == 3); + const auto& cs = s; + auto cer = cs.equal_range(1); + assert(cer.first == er.first); + assert(cer.second == er.second); + return 0; } diff --git a/libcxx/test/std/containers/unord/unord.map/count_transparent.pass.cpp b/libcxx/test/std/containers/unord/unord.map/count_transparent.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/count_transparent.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// class unordered_map + +// template +// size_type count(const K& x) const; // C++20 + +#include +#include +#include + +struct Hash { + using is_transparent = void; + + bool operator()(const std::pair& x) const { + return std::hash()(x.first); + } + bool operator()(int x) const { + return std::hash()(x); + } +}; + +struct Eq { + using is_transparent = void; + + bool operator()(const std::pair& lhs, + const std::pair& rhs) const { + return lhs == rhs; + } + + bool operator()(const std::pair& lhs, int rhs) const { + return lhs.first == rhs; + } + + bool operator()(int lhs, const std::pair& rhs) const { + return lhs == rhs.first; + } +}; + +int main(int, char**) { + std::unordered_map, int, Hash, Eq> m = { + {{2, 1}, 1}, {{1, 2}, 2}, {{1, 3}, 3}, {{1, 4}, 4}, {{2, 2}, 5} + }; + + auto cnt = m.count(1); + assert(cnt == 3); + + return 0; +} diff --git a/libcxx/test/std/containers/unord/unord.map/equal_range_transparent.pass.cpp b/libcxx/test/std/containers/unord/unord.map/equal_range_transparent.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/equal_range_transparent.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// class unordered_map + +// template +// pair equal_range(const K& x); // C++20 +// template +// pair equal_range(const K& x) const; // C++20 + +#include +#include +#include + +struct Hash { + using is_transparent = void; + + bool operator()(const std::pair& x) const { + return std::hash()(x.first); + } + bool operator()(int x) const { + return std::hash()(x); + } +}; + +struct Eq { + using is_transparent = void; + + bool operator()(const std::pair& lhs, + const std::pair& rhs) const { + return lhs == rhs; + } + + bool operator()(const std::pair& lhs, int rhs) const { + return lhs.first == rhs; + } + + bool operator()(int lhs, const std::pair& rhs) const { + return lhs == rhs.first; + } +}; + +int main(int, char**) { + std::unordered_map, int, Hash, Eq> m = { + {{2, 1}, 1}, {{1, 2}, 2}, {{1, 3}, 3}, {{1, 4}, 4}, {{2, 2}, 5} + }; + + auto er = m.equal_range(1); + long nels = 0; + + for (auto it = er.first; it != er.second; it++) { + assert(it->first.first == 1); + nels++; + } + assert(nels == 3); + + const auto& cm = m; + auto cer = cm.equal_range(1); + assert(cer.first == er.first); + assert(cer.second == er.second); + + return 0; +} diff --git a/libcxx/test/std/containers/unord/unord.set/count_transparent.pass.cpp b/libcxx/test/std/containers/unord/unord.set/count_transparent.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/count_transparent.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// class unordered_set + +// template +// size_type count(const K& x) const; // C++20 + +#include + +#include +#include + +struct Hash { + using is_transparent = void; + + bool operator()(const std::pair& x) const { + return std::hash()(x.first); + } + bool operator()(int x) const { + return std::hash()(x); + } +}; + +struct Eq { + using is_transparent = void; + + bool operator()(const std::pair& lhs, + const std::pair& rhs) const { + return lhs == rhs; + } + + bool operator()(const std::pair& lhs, int rhs) const { + return lhs.first == rhs; + } + + bool operator()(int lhs, const std::pair& rhs) const { + return lhs == rhs.first; + } +}; + +int main(int, char**) { + std::unordered_set, Hash, Eq> s{{2, 1}, {1, 2}, {1, 3}, {1, 4}, {2, 2}}; + + auto cnt = s.count(1); + assert(cnt == 3); + + return 0; +} diff --git a/libcxx/test/std/containers/unord/unord.set/equal_range_transparent.pass.cpp b/libcxx/test/std/containers/unord/unord.set/equal_range_transparent.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/equal_range_transparent.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// class unordered_set + +// template +// pair equal_range(const K& x); // C++20 +// template +// pair equal_range(const K& x) const; // C++20 + +#include +#include +#include + +struct Hash { + using is_transparent = void; + + bool operator()(const std::pair& x) const { + return std::hash()(x.first); + } + bool operator()(int x) const { + return std::hash()(x); + } +}; + +struct Eq { + using is_transparent = void; + + bool operator()(const std::pair& lhs, + const std::pair& rhs) const { + return lhs == rhs; + } + + bool operator()(const std::pair& lhs, int rhs) const { + return lhs.first == rhs; + } + + bool operator()(int lhs, const std::pair& rhs) const { + return lhs == rhs.first; + } +}; + +int main(int, char**) { + std::unordered_set, Hash, Eq> s{{2, 1}, {1, 2}, {1, 3}, {1, 4}, {2, 2}}; + + auto er = s.equal_range(1); + long nels = 0; + + for (auto it = er.first; it != er.second; it++) { + assert(it->first == 1); + nels++; + } + assert(nels == 3); + + const auto& cs = s; + auto cer = cs.equal_range(1); + assert(cer.first == er.first); + assert(cer.second == er.second); + + return 0; +}