mirror of
https://github.com/boostorg/unordered.git
synced 2025-07-29 19:07:15 +02:00
Add contains_tests
This commit is contained in:
@ -11,6 +11,7 @@
|
||||
#endif
|
||||
|
||||
#include <boost/unordered/detail/foa.hpp>
|
||||
#include <boost/unordered/detail/type_traits.hpp>
|
||||
#include <boost/unordered/unordered_flat_map_fwd.hpp>
|
||||
|
||||
#include <boost/core/allocator_access.hpp>
|
||||
@ -332,11 +333,38 @@ namespace boost {
|
||||
return table_.find(key);
|
||||
}
|
||||
|
||||
template <class K>
|
||||
typename std::enable_if<
|
||||
boost::unordered::detail::are_transparent<K, hasher, key_equal>::value,
|
||||
iterator>::type
|
||||
find(K const& key)
|
||||
{
|
||||
return table_.find(key);
|
||||
}
|
||||
|
||||
template <class K>
|
||||
typename std::enable_if<
|
||||
boost::unordered::detail::are_transparent<K, hasher, key_equal>::value,
|
||||
const_iterator>::type
|
||||
find(K const& key) const
|
||||
{
|
||||
return table_.find(key);
|
||||
}
|
||||
|
||||
bool contains(key_type const& key) const
|
||||
{
|
||||
return this->find(key) != this->end();
|
||||
}
|
||||
|
||||
template <class K>
|
||||
typename std::enable_if<
|
||||
boost::unordered::detail::are_transparent<K, hasher, key_equal>::value,
|
||||
bool>::type
|
||||
contains(K const& key) const
|
||||
{
|
||||
return this->find(key) != this->end();
|
||||
}
|
||||
|
||||
std::pair<iterator, iterator> equal_range(key_type const& key)
|
||||
{
|
||||
auto pos = table_.find(key);
|
||||
|
@ -11,6 +11,7 @@
|
||||
#endif
|
||||
|
||||
#include <boost/unordered/detail/foa.hpp>
|
||||
#include <boost/unordered/detail/type_traits.hpp>
|
||||
#include <boost/unordered/unordered_flat_set_fwd.hpp>
|
||||
|
||||
#include <boost/core/allocator_access.hpp>
|
||||
@ -229,6 +230,38 @@ namespace boost {
|
||||
return table_.find(key);
|
||||
}
|
||||
|
||||
template <class K>
|
||||
typename std::enable_if<
|
||||
boost::unordered::detail::are_transparent<K, hasher, key_equal>::value,
|
||||
iterator>::type
|
||||
find(K const& key)
|
||||
{
|
||||
return table_.find(key);
|
||||
}
|
||||
|
||||
template <class K>
|
||||
typename std::enable_if<
|
||||
boost::unordered::detail::are_transparent<K, hasher, key_equal>::value,
|
||||
const_iterator>::type
|
||||
find(K const& key) const
|
||||
{
|
||||
return table_.find(key);
|
||||
}
|
||||
|
||||
bool contains(key_type const& key) const
|
||||
{
|
||||
return this->find(key) != this->end();
|
||||
}
|
||||
|
||||
template <class K>
|
||||
typename std::enable_if<
|
||||
boost::unordered::detail::are_transparent<K, hasher, key_equal>::value,
|
||||
bool>::type
|
||||
contains(K const& key) const
|
||||
{
|
||||
return this->find(key) != this->end();
|
||||
}
|
||||
|
||||
std::pair<iterator, iterator> equal_range(key_type const& key)
|
||||
{
|
||||
auto pos = table_.find(key);
|
||||
|
@ -114,4 +114,5 @@ build_foa find_tests ;
|
||||
build_foa at_tests ;
|
||||
build_foa load_factor_tests ;
|
||||
build_foa rehash_tests ;
|
||||
build_foa contains_tests ;
|
||||
build_foa equality_tests ;
|
||||
|
@ -4,8 +4,14 @@
|
||||
|
||||
// clang-format off
|
||||
#include "../helpers/prefix.hpp"
|
||||
#ifdef BOOST_UNORDERED_FOA_TESTS
|
||||
#include <boost/unordered/unordered_flat_set.hpp>
|
||||
#include <boost/unordered/unordered_flat_map.hpp>
|
||||
#include <boost/unordered/detail/implementation.hpp>
|
||||
#else
|
||||
#include <boost/unordered_set.hpp>
|
||||
#include <boost/unordered_map.hpp>
|
||||
#endif
|
||||
#include "../helpers/postfix.hpp"
|
||||
// clang-format on
|
||||
|
||||
@ -129,6 +135,20 @@ template <class UnorderedMap> void test_map_non_transparent_contains()
|
||||
|
||||
void test_map()
|
||||
{
|
||||
#ifdef BOOST_UNORDERED_FOA_TESTS
|
||||
typedef boost::unordered_flat_map<key, int, transparent_hasher,
|
||||
transparent_key_equal>
|
||||
transparent_map;
|
||||
|
||||
typedef boost::unordered_flat_map<key, int, transparent_hasher, key_equal>
|
||||
non_transparent_map1;
|
||||
|
||||
typedef boost::unordered_flat_map<key, int, hasher, transparent_key_equal>
|
||||
non_transparent_map2;
|
||||
|
||||
typedef boost::unordered_flat_map<key, int, hasher, key_equal>
|
||||
non_transparent_map3;
|
||||
#else
|
||||
typedef boost::unordered_map<key, int, transparent_hasher,
|
||||
transparent_key_equal>
|
||||
transparent_map;
|
||||
@ -141,6 +161,7 @@ void test_map()
|
||||
|
||||
typedef boost::unordered_map<key, int, hasher, key_equal>
|
||||
non_transparent_map3;
|
||||
#endif
|
||||
|
||||
test_map_transparent_contains<transparent_map>();
|
||||
test_map_non_transparent_contains<non_transparent_map1>();
|
||||
@ -148,6 +169,7 @@ void test_map()
|
||||
test_map_non_transparent_contains<non_transparent_map3>();
|
||||
}
|
||||
|
||||
#ifndef BOOST_UNORDERED_FOA_TESTS
|
||||
void test_multimap()
|
||||
{
|
||||
typedef boost::unordered_multimap<key, int, transparent_hasher,
|
||||
@ -168,6 +190,7 @@ void test_multimap()
|
||||
test_map_non_transparent_contains<non_transparent_multimap2>();
|
||||
test_map_non_transparent_contains<non_transparent_multimap3>();
|
||||
}
|
||||
#endif
|
||||
|
||||
template <class UnorderedSet> void test_set_transparent_contains()
|
||||
{
|
||||
@ -231,6 +254,18 @@ template <class UnorderedSet> void test_set_non_transparent_contains()
|
||||
|
||||
void test_set()
|
||||
{
|
||||
#ifdef BOOST_UNORDERED_FOA_TESTS
|
||||
typedef boost::unordered_flat_set<key, transparent_hasher,
|
||||
transparent_key_equal>
|
||||
transparent_set;
|
||||
|
||||
typedef boost::unordered_flat_set<key, transparent_hasher, key_equal>
|
||||
non_transparent_set1;
|
||||
typedef boost::unordered_flat_set<key, hasher, transparent_key_equal>
|
||||
non_transparent_set2;
|
||||
typedef boost::unordered_flat_set<key, hasher, key_equal>
|
||||
non_transparent_set3;
|
||||
#else
|
||||
typedef boost::unordered_set<key, transparent_hasher, transparent_key_equal>
|
||||
transparent_set;
|
||||
|
||||
@ -239,6 +274,7 @@ void test_set()
|
||||
typedef boost::unordered_set<key, hasher, transparent_key_equal>
|
||||
non_transparent_set2;
|
||||
typedef boost::unordered_set<key, hasher, key_equal> non_transparent_set3;
|
||||
#endif
|
||||
|
||||
test_set_transparent_contains<transparent_set>();
|
||||
test_set_non_transparent_contains<non_transparent_set1>();
|
||||
@ -246,6 +282,7 @@ void test_set()
|
||||
test_set_non_transparent_contains<non_transparent_set3>();
|
||||
}
|
||||
|
||||
#ifndef BOOST_UNORDERED_FOA_TESTS
|
||||
void test_multiset()
|
||||
{
|
||||
typedef boost::unordered_multiset<key, transparent_hasher,
|
||||
@ -264,11 +301,15 @@ void test_multiset()
|
||||
test_set_non_transparent_contains<non_transparent_multiset2>();
|
||||
test_set_non_transparent_contains<non_transparent_multiset3>();
|
||||
}
|
||||
#endif
|
||||
|
||||
UNORDERED_AUTO_TEST (contains_) { // avoid -Wshadow warning with `bool contains`
|
||||
test_map();
|
||||
test_multimap();
|
||||
test_set();
|
||||
#ifndef BOOST_UNORDERED_FOA_TESTS
|
||||
test_multimap();
|
||||
test_multiset();
|
||||
#endif
|
||||
}
|
||||
|
||||
RUN_TESTS()
|
||||
|
Reference in New Issue
Block a user