Index: libcxx/include/unordered_map =================================================================== --- libcxx/include/unordered_map +++ libcxx/include/unordered_map @@ -183,6 +183,8 @@ mapped_type& at(const key_type& k); const mapped_type& at(const key_type& k) const; + bool contains(const key_type& k) const; // C++20 + size_type bucket_count() const noexcept; size_type max_bucket_count() const noexcept; @@ -358,6 +360,8 @@ pair equal_range(const key_type& k); pair equal_range(const key_type& k) const; + bool contains(const key_type& k) const; // C++20 + size_type bucket_count() const noexcept; size_type max_bucket_count() const noexcept; @@ -1290,6 +1294,11 @@ mapped_type& at(const key_type& __k); const mapped_type& at(const key_type& __k) const; +#if _LIBCPP_STD_VER > 17 + _LIBCPP_INLINE_VISIBILITY + bool contains(const key_type& __k) const { return __table_.find(__k) != __table_.end(); } +#endif + _LIBCPP_INLINE_VISIBILITY size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();} _LIBCPP_INLINE_VISIBILITY @@ -1983,6 +1992,12 @@ pair equal_range(const key_type& __k) const {return __table_.__equal_range_multi(__k);} +#if _LIBCPP_STD_VER > 17 + _LIBCPP_INLINE_VISIBILITY + bool contains(const key_type& __k) const + { return __table_.find(__k) != __table_.end(); } +#endif + _LIBCPP_INLINE_VISIBILITY size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();} _LIBCPP_INLINE_VISIBILITY Index: libcxx/include/unordered_set =================================================================== --- libcxx/include/unordered_set +++ libcxx/include/unordered_set @@ -149,6 +149,8 @@ pair equal_range(const key_type& k); pair equal_range(const key_type& k) const; + bool contains(const key_type& k) const; // C++20 + size_type bucket_count() const noexcept; size_type max_bucket_count() const noexcept; @@ -313,6 +315,8 @@ pair equal_range(const key_type& k); pair equal_range(const key_type& k) const; + bool contains(const key_type& k) const; // C++20 + size_type bucket_count() const noexcept; size_type max_bucket_count() const noexcept; @@ -681,6 +685,12 @@ pair equal_range(const key_type& __k) const {return __table_.__equal_range_unique(__k);} +#if _LIBCPP_STD_VER > 17 + _LIBCPP_INLINE_VISIBILITY + bool contains(const key_type& __k) const + { return __table_.find(__k) != __table_.end(); } +#endif + _LIBCPP_INLINE_VISIBILITY size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();} _LIBCPP_INLINE_VISIBILITY @@ -1249,6 +1259,12 @@ pair equal_range(const key_type& __k) const {return __table_.__equal_range_multi(__k);} +#if _LIBCPP_STD_VER > 17 + _LIBCPP_INLINE_VISIBILITY + bool contains(const key_type& __k) const + { return __table_.find(__k) != __table_.end(); } +#endif + _LIBCPP_INLINE_VISIBILITY size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();} _LIBCPP_INLINE_VISIBILITY Index: libcxx/test/std/containers/unord/unord.map/contains.pass.cpp =================================================================== --- /dev/null +++ libcxx/test/std/containers/unord/unord.map/contains.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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++98, c++03, c++11, c++14, c++17 +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// bool contains(const key_type& k) const; + +#include +#include +#include + +int main(int, char**) +{ + std::unordered_map c{}; + assert(!c.contains(1)); + + c[1] = "one"; + assert(c.contains(1)); + + return 0; +} Index: libcxx/test/std/containers/unord/unord.multimap/contains.pass.cpp =================================================================== --- /dev/null +++ libcxx/test/std/containers/unord/unord.multimap/contains.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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++98, c++03, c++11, c++14, c++17 +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// bool contains(const key_type& k) const; + +#include +#include +#include + +int main(int, char**) +{ + std::unordered_multimap c{}; + assert(!c.contains(1)); + + c.insert({1, "one"}); + assert(c.contains(1)); + + return 0; +} Index: libcxx/test/std/containers/unord/unord.multiset/contains.pass.cpp =================================================================== --- /dev/null +++ libcxx/test/std/containers/unord/unord.multiset/contains.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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++98, c++03, c++11, c++14, c++17 +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// bool contains(const key_type& k) const; + +#include +#include + +int main(int, char**) +{ + std::unordered_multiset c{}; + assert(!c.contains(1)); + + c.insert(1); + assert(c.contains(1)); + + return 0; +} Index: libcxx/test/std/containers/unord/unord.set/contains.pass.cpp =================================================================== --- /dev/null +++ libcxx/test/std/containers/unord/unord.set/contains.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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++98, c++03, c++11, c++14, c++17 +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// bool contains(const key_type& k) const; + +#include +#include + +int main(int, char**) +{ + std::unordered_set c{}; + assert(!c.contains(1)); + + c.insert(1); + assert(c.contains(1)); + + return 0; +}