forked from qt-creator/qt-creator
Algorithms: Introduce helper Utils::equal
Takes a member (function) pointer and a value and returns a functor, that takes a instance of the mfp's class and returns whether it's equal to value. Sounds complicated, but is a common pattern that is easy to understand. Change-Id: Iaaeb90488d34ddfd6940dadd4c66705381198fee Reviewed-by: Nikita Baryshnikov <nib952051@gmail.com> Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
@@ -121,6 +121,23 @@ typename T::value_type findOrDefault(const T &container, F function)
|
||||
return findOr(container, typename T::value_type(), function);
|
||||
}
|
||||
|
||||
//////////////////
|
||||
// find helpers
|
||||
//////////////////
|
||||
template<typename R, typename S, typename T>
|
||||
auto equal(R (S::*function)() const, T value)
|
||||
-> decltype(std::bind<bool>(std::equal_to<T>(), value, std::bind(function, std::placeholders::_1)))
|
||||
{
|
||||
return std::bind<bool>(std::equal_to<T>(), value, std::bind(function, std::placeholders::_1));
|
||||
}
|
||||
|
||||
template<typename R, typename S, typename T>
|
||||
auto equal(R (S::*member), T value)
|
||||
-> decltype(std::bind<bool>(std::equal_to<T>(), value, std::bind(member, std::placeholders::_1)))
|
||||
{
|
||||
return std::bind<bool>(std::equal_to<T>(), value, std::bind(member, std::placeholders::_1));
|
||||
}
|
||||
|
||||
//////////////////
|
||||
// transform
|
||||
/////////////////
|
||||
|
||||
Reference in New Issue
Block a user