Merge branch 'pull-request/#990-Add-contains-method-to-etl-unordered_map-and-etl-unordered_set' into development

This commit is contained in:
John Wellbelove 2024-12-19 18:16:39 +00:00
commit 4cbef7fb6e
8 changed files with 168 additions and 0 deletions

View File

@ -1681,6 +1681,25 @@ namespace etl
}
#endif
//*************************************************************************
/// Check if the unordered_map contains the key.
//*************************************************************************
bool contains(const_key_reference key) const
{
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

@ -1442,6 +1442,25 @@ namespace etl
}
#endif
//*************************************************************************
/// Check if the unordered_multimap contains the key.
//*************************************************************************
bool contains(const_key_reference key) const
{
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

@ -1493,6 +1493,25 @@ namespace etl
}
#endif
//*************************************************************************
/// Check if the unordered_multiset contains the key.
//*************************************************************************
bool contains(key_parameter_t key) const
{
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

@ -1502,6 +1502,25 @@ namespace etl
}
#endif
//*************************************************************************
/// Check if the unordered_set contains the key.
//*************************************************************************
bool contains(key_parameter_t key) const
{
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

@ -1409,5 +1409,27 @@ namespace
CHECK_TRUE(map1 == map2a);
CHECK_FALSE(map1 == map2b);
}
//*************************************************************************
TEST(test_contains)
{
DataNDC data(initial_data.begin(), initial_data.end());
const char* not_inserted = "ZZ";
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

@ -1226,5 +1226,27 @@ namespace
CHECK_TRUE(map1 == map2a);
CHECK_FALSE(map1 == map2b);
}
//*************************************************************************
TEST(test_contains)
{
DataNDC data(initial_data.begin(), initial_data.end());
const char* not_inserted = "ZZ";
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

@ -1079,5 +1079,29 @@ namespace
CHECK_TRUE(set1 == set2a);
CHECK_FALSE(set1 == set2b);
}
//*************************************************************************
TEST(test_contains)
{
DataNDC data(initial_data.begin(), initial_data.end());
NDC not_inserted = NDC("ZZ");
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

@ -1044,5 +1044,29 @@ namespace
CHECK_TRUE(set1 == set2a);
CHECK_FALSE(set1 == set2b);
}
//*************************************************************************
TEST(test_contains)
{
DataNDC data(initial_data.begin(), initial_data.end());
NDC not_inserted = NDC("ZZ");
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));
}
};
}