Added transparent comparator overloads of contains()

This commit is contained in:
John Wellbelove 2024-12-19 16:20:48 +00:00
parent 1daa345038
commit 191eaae225
8 changed files with 96 additions and 4 deletions

View File

@ -1689,6 +1689,17 @@ namespace etl
return find(key) != end();
}
#if ETL_USING_CPP11
//*************************************************************************
/// Check if the unordered_map contains the key.
//*************************************************************************
template <typename K, typename KE = TKeyEqual, etl::enable_if_t<comparator_is_transparent<KE>::value, int> = 0>
bool contains(const K& key) const
{
return find(key) != end();
}
#endif
protected:
//*********************************************************************

View File

@ -1450,6 +1450,17 @@ namespace etl
return find(key) != end();
}
#if ETL_USING_CPP11
//*************************************************************************
/// Check if the unordered_map contains the key.
//*************************************************************************
template <typename K, typename KE = TKeyEqual, etl::enable_if_t<comparator_is_transparent<KE>::value, int> = 0>
bool contains(const K& key) const
{
return find(key) != end();
}
#endif
protected:
//*********************************************************************

View File

@ -1501,6 +1501,17 @@ namespace etl
return find(key) != end();
}
#if ETL_USING_CPP11
//*************************************************************************
/// Check if the unordered_map contains the key.
//*************************************************************************
template <typename K, typename KE = TKeyEqual, etl::enable_if_t<comparator_is_transparent<KE>::value, int> = 0>
bool contains(const K& key) const
{
return find(key) != end();
}
#endif
protected:
//*********************************************************************

View File

@ -1510,6 +1510,17 @@ namespace etl
return find(key) != end();
}
#if ETL_USING_CPP11
//*************************************************************************
/// Check if the unordered_map contains the key.
//*************************************************************************
template <typename K, typename KE = TKeyEqual, etl::enable_if_t<comparator_is_transparent<KE>::value, int> = 0>
bool contains(const K& key) const
{
return find(key) != end();
}
#endif
protected:
//*********************************************************************

View File

@ -1417,8 +1417,19 @@ namespace
const char* not_inserted = "ZZ";
CHECK(data.contains(std::string(K0)));
CHECK(!data.contains(std::string(not_inserted)));
CHECK_TRUE(data.contains(K0));
CHECK_FALSE(data.contains(std::string(not_inserted)));
}
//*************************************************************************
TEST(test_contains_with_transparent_comparator)
{
DataNDCTransparent data(initial_data.begin(), initial_data.end());
const char* not_inserted = "ZZ";
CHECK_TRUE(data.contains("FF"));
CHECK_FALSE(data.contains(not_inserted));
}
};
}

View File

@ -1234,8 +1234,19 @@ namespace
const char* not_inserted = "ZZ";
CHECK(data.contains(K0));
CHECK(!data.contains(not_inserted));
CHECK_TRUE(data.contains(K0));
CHECK_FALSE(data.contains(not_inserted));
}
//*************************************************************************
TEST(test_contains_with_transparent_comparator)
{
DataNDCTransparent data(initial_data.begin(), initial_data.end());
const char* not_inserted = "ZZ";
CHECK_TRUE(data.contains("FF"));
CHECK_FALSE(data.contains(not_inserted));
}
};
}

View File

@ -1090,5 +1090,18 @@ namespace
CHECK_TRUE(data.contains(N0));
CHECK_FALSE(data.contains(not_inserted));
}
//*************************************************************************
TEST(test_contains_with_transparent_comparator)
{
std::array<const char*, 8> initial = { "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH" };
DataTransparent data(initial.begin(), initial.end());
const char* not_inserted = "ZZ";
CHECK_TRUE(data.contains("FF"));
CHECK_FALSE(data.contains(not_inserted));
}
};
}

View File

@ -1055,5 +1055,18 @@ namespace
CHECK_TRUE(data.contains(N0));
CHECK_FALSE(data.contains(not_inserted));
}
//*************************************************************************
TEST(test_contains_with_transparent_comparator)
{
std::array<const char*, 8> initial = { "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH" };
DataTransparent data(initial.begin(), initial.end());
const char* not_inserted = "ZZ";
CHECK_TRUE(data.contains("FF"));
CHECK_FALSE(data.contains(not_inserted));
}
};
}