Boost logo

Boost Users :

From: Matthias Kaeppler (nospam_at_[hidden])
Date: 2005-03-04 12:38:20


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<bool ()(int&)>':
code/FileBrowser.cpp:90: instantiated from here
code/ext/indirect.hpp:80: error: forming pointer to reference type `int&'

Line 80 is the line where operator() is defined. The error message
indicates that argument_type is obviously not correct in this context.
I thought the boost traits would take care of the right argument types?
Am I missing something?

-- 
Matthias Kaeppler

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net