mirror of
https://github.com/BlackMATov/flat.hpp.git
synced 2025-12-13 01:36:27 +07:00
add contains function #25
This commit is contained in:
@@ -508,6 +508,18 @@ namespace flat_hpp
|
||||
: end();
|
||||
}
|
||||
|
||||
bool contains(const key_type& key) const {
|
||||
return find(key) != end();
|
||||
}
|
||||
|
||||
template < typename K >
|
||||
std::enable_if_t<
|
||||
detail::is_transparent_v<Compare, K>,
|
||||
bool>
|
||||
contains(const K& key) const {
|
||||
return find(key) != end();
|
||||
}
|
||||
|
||||
std::pair<iterator, iterator> equal_range(const key_type& key) {
|
||||
const base_type& comp = *this;
|
||||
return std::equal_range(begin(), end(), key, comp);
|
||||
|
||||
@@ -458,6 +458,18 @@ namespace flat_hpp
|
||||
: end();
|
||||
}
|
||||
|
||||
bool contains(const key_type& key) const {
|
||||
return find(key) != end();
|
||||
}
|
||||
|
||||
template < typename K >
|
||||
std::enable_if_t<
|
||||
detail::is_transparent_v<Compare, K>,
|
||||
bool>
|
||||
contains(const K& key) const {
|
||||
return find(key) != end();
|
||||
}
|
||||
|
||||
std::pair<iterator, iterator> equal_range(const key_type& key) {
|
||||
const base_type& comp = *this;
|
||||
return std::equal_range(begin(), end(), key, comp);
|
||||
|
||||
@@ -386,6 +386,18 @@ namespace flat_hpp
|
||||
: end();
|
||||
}
|
||||
|
||||
bool contains(const key_type& key) const {
|
||||
return find(key) != end();
|
||||
}
|
||||
|
||||
template < typename K >
|
||||
std::enable_if_t<
|
||||
detail::is_transparent_v<Compare, K>,
|
||||
bool>
|
||||
contains(const K& key) const {
|
||||
return find(key) != end();
|
||||
}
|
||||
|
||||
std::pair<iterator, iterator> equal_range(const key_type& key) {
|
||||
return std::equal_range(begin(), end(), key, key_comp());
|
||||
}
|
||||
|
||||
@@ -436,6 +436,18 @@ namespace flat_hpp
|
||||
: end();
|
||||
}
|
||||
|
||||
bool contains(const key_type& key) const {
|
||||
return find(key) != end();
|
||||
}
|
||||
|
||||
template < typename K >
|
||||
std::enable_if_t<
|
||||
detail::is_transparent_v<Compare, K>,
|
||||
bool>
|
||||
contains(const K& key) const {
|
||||
return find(key) != end();
|
||||
}
|
||||
|
||||
std::pair<iterator, iterator> equal_range(const key_type& key) {
|
||||
return std::equal_range(begin(), end(), key, key_comp());
|
||||
}
|
||||
|
||||
@@ -421,6 +421,9 @@ TEST_CASE("flat_map") {
|
||||
REQUIRE(my_as_const(s0).find(3) == s0.cbegin() + 2);
|
||||
REQUIRE(s0.find(6) == s0.end());
|
||||
REQUIRE(my_as_const(s0).find(0) == s0.cend());
|
||||
REQUIRE(my_as_const(s0).contains(1));
|
||||
REQUIRE(my_as_const(s0).contains(3));
|
||||
REQUIRE_FALSE(my_as_const(s0).contains(0));
|
||||
}
|
||||
{
|
||||
map_t s0{{1,2},{2,3},{3,4},{4,5},{5,6}};
|
||||
@@ -445,6 +448,9 @@ TEST_CASE("flat_map") {
|
||||
REQUIRE(s0.find(std::string_view("42")) == s0.end());
|
||||
REQUIRE(my_as_const(s0).find(std::string_view("42")) == s0.cend());
|
||||
|
||||
REQUIRE(my_as_const(s0).contains(std::string_view("hello")));
|
||||
REQUIRE_FALSE(my_as_const(s0).contains(std::string_view("42")));
|
||||
|
||||
REQUIRE(my_as_const(s0).count(std::string_view("hello")) == 1);
|
||||
REQUIRE(my_as_const(s0).count(std::string_view("hello_42")) == 0);
|
||||
|
||||
|
||||
@@ -423,6 +423,9 @@ TEST_CASE("flat_multimap") {
|
||||
REQUIRE(my_as_const(s0).find(3) == s0.cbegin() + 2);
|
||||
REQUIRE(s0.find(6) == s0.end());
|
||||
REQUIRE(my_as_const(s0).find(0) == s0.cend());
|
||||
REQUIRE(my_as_const(s0).contains(1));
|
||||
REQUIRE(my_as_const(s0).contains(3));
|
||||
REQUIRE_FALSE(my_as_const(s0).contains(0));
|
||||
}
|
||||
{
|
||||
map_t s0{{1,2},{2,3},{2,1},{3,4},{4,5},{5,6}};
|
||||
@@ -447,6 +450,9 @@ TEST_CASE("flat_multimap") {
|
||||
REQUIRE(s0.find(std::string_view("42")) == s0.end());
|
||||
REQUIRE(my_as_const(s0).find(std::string_view("42")) == s0.cend());
|
||||
|
||||
REQUIRE(my_as_const(s0).contains(std::string_view("hello")));
|
||||
REQUIRE_FALSE(my_as_const(s0).contains(std::string_view("42")));
|
||||
|
||||
REQUIRE(my_as_const(s0).count(std::string_view("hello")) == 1);
|
||||
REQUIRE(my_as_const(s0).count(std::string_view("hello_42")) == 0);
|
||||
|
||||
|
||||
@@ -399,6 +399,9 @@ TEST_CASE("flat_multiset") {
|
||||
REQUIRE(my_as_const(s0).find(3) == s0.cbegin() + 2);
|
||||
REQUIRE(s0.find(6) == s0.end());
|
||||
REQUIRE(my_as_const(s0).find(0) == s0.cend());
|
||||
REQUIRE(my_as_const(s0).contains(1));
|
||||
REQUIRE(my_as_const(s0).contains(3));
|
||||
REQUIRE_FALSE(my_as_const(s0).contains(0));
|
||||
}
|
||||
{
|
||||
set_t s0{1,2,3,3,4,5};
|
||||
@@ -423,6 +426,9 @@ TEST_CASE("flat_multiset") {
|
||||
REQUIRE(s0.find(std::string_view("42")) == s0.end());
|
||||
REQUIRE(my_as_const(s0).find(std::string_view("42")) == s0.cend());
|
||||
|
||||
REQUIRE(my_as_const(s0).contains(std::string_view("hello")));
|
||||
REQUIRE_FALSE(my_as_const(s0).contains(std::string_view("42")));
|
||||
|
||||
REQUIRE(my_as_const(s0).count(std::string_view("hello")) == 1);
|
||||
REQUIRE(my_as_const(s0).count(std::string_view("hello_42")) == 0);
|
||||
|
||||
|
||||
@@ -397,6 +397,9 @@ TEST_CASE("flat_set") {
|
||||
REQUIRE(my_as_const(s0).find(3) == s0.cbegin() + 2);
|
||||
REQUIRE(s0.find(6) == s0.end());
|
||||
REQUIRE(my_as_const(s0).find(0) == s0.cend());
|
||||
REQUIRE(my_as_const(s0).contains(1));
|
||||
REQUIRE(my_as_const(s0).contains(3));
|
||||
REQUIRE_FALSE(my_as_const(s0).contains(0));
|
||||
}
|
||||
{
|
||||
set_t s0{1,2,3,4,5};
|
||||
@@ -421,6 +424,9 @@ TEST_CASE("flat_set") {
|
||||
REQUIRE(s0.find(std::string_view("42")) == s0.end());
|
||||
REQUIRE(my_as_const(s0).find(std::string_view("42")) == s0.cend());
|
||||
|
||||
REQUIRE(my_as_const(s0).contains(std::string_view("hello")));
|
||||
REQUIRE_FALSE(my_as_const(s0).contains(std::string_view("42")));
|
||||
|
||||
REQUIRE(my_as_const(s0).count(std::string_view("hello")) == 1);
|
||||
REQUIRE(my_as_const(s0).count(std::string_view("hello_42")) == 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user