I am not aware of any functional object in the standard C ++ library or in Boost that does this (which does not mean that it is not there, I am not familiar with everything in Boost libraries: -P).
However, writing your own is easy enough. Consider the following:
template <typename Predicate> class indirect_binary_predicate { public: indirect_binary_predicate(const Predicate& pred = Predicate()) : pred_(pred) { } template <typename Argument0, typename Argument1> bool operator()(Argument0 arg0, Argument1 arg1) const { return pred_(*arg0, *arg1); } private: Predicate pred_; };
Usage example:
std::set<int*, indirect_binary_predicate<std::equal_to<int> > > s;
Please note that it is not recommended to have a container with unprocessed pointers if pointers are designed for dynamically distributed objects, and the container has ownership of objects with a pointer to objects; this is not an exception - it is safe. However, this predicate adapter should work just as well for smart pointers, iterators, or any other type that supports dereferencing.
source share