mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-23 04:16:04 +08:00
Added transparent comparator overloads of contains()
This commit is contained in:
parent
1daa345038
commit
191eaae225
@ -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:
|
||||
|
||||
//*********************************************************************
|
||||
|
||||
@ -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:
|
||||
|
||||
//*********************************************************************
|
||||
|
||||
@ -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:
|
||||
|
||||
//*********************************************************************
|
||||
|
||||
@ -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:
|
||||
|
||||
//*********************************************************************
|
||||
|
||||
@ -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));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -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));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -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));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -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));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user