Hello,
I have written an adaptor for functions and function objects which
allows to invoke operations on the pointees when working on a collection
of pointers. For example, it allows to sort a list of pointers by a
predicate applying to the pointees.
To make it work with normal functions and functors, I utilized
boost::unary_traits and boost::binary_traits.
This is the class template for the unary version:
template< typename Operation >
class indirecter_unary
: public std::unary_function< typename
boost::unary_traits<Operation>::argument_type,
typename boost::unary_traits<Operation>::result_type >
{
typedef typename boost::unary_traits<Operation>::argument_type arg_type;
typedef typename boost::unary_traits<Operation>::param_type
param_type;
typedef typename boost::unary_traits<Operation>::result_type
result_type;
typedef typename boost::unary_traits<Operation>::function_type
function_type;
function_type op_;
public:
explicit indirecter_unary( param_type op ): op_(op) {}
result_type operator() (arg_type *arg) const {
return op_(*arg);
}
};
Now, the problem arises when I pass a function which takes references.
Like this:
bool pred( int& a )
{
//...
}
indirecter_unary< bool ()(int&) > fctor(pred);
ext::indirecter_unary