Created
September 2, 2018 17:43
-
-
Save Furkanzmc/8533db807fd96f3750d94846da3f6954 to your computer and use it in GitHub Desktop.
DRY Multicomparisons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <typename Type, typename ComparisonFunc = std::equal_to<Type>> | |
class is | |
{ | |
public: | |
constexpr is(Type t) | |
: m_Value(std::move(t)) | |
{} | |
bool any_of(const std::initializer_list<Type> &list) const | |
{ | |
return std::any_of(list.begin(), list.end(), std::bind(ComparisonFunc(), m_Value, std::placeholders::_1)); | |
} | |
bool any_of(const std::initializer_list<Type> &&list) const | |
{ | |
return std::any_of(list.begin(), list.end(), std::bind(ComparisonFunc(), m_Value, std::placeholders::_1)); | |
} | |
bool all_of(const std::initializer_list<Type> &list) const | |
{ | |
return std::all_of(list.begin(), list.end(), std::bind(ComparisonFunc(), m_Value, std::placeholders::_1)); | |
} | |
bool all_of(const std::initializer_list<Type> &&list) const | |
{ | |
return std::all_of(list.begin(), list.end(), std::bind(ComparisonFunc(), m_Value, std::placeholders::_1)); | |
} | |
bool none_of(const std::initializer_list<Type> &list) const | |
{ | |
return std::none_of(list.begin(), list.end(), std::bind(ComparisonFunc(), m_Value, std::placeholders::_1)); | |
} | |
bool none_of(const std::initializer_list<Type> &&list) const | |
{ | |
return std::none_of(list.begin(), list.end(), std::bind(ComparisonFunc(), m_Value, std::placeholders::_1)); | |
} | |
private: | |
Type m_Value; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example Usage: