libzypp  17.8.0
zypp::functor::functor_detail Namespace Reference

An unary functor forwarding to some other TFunctor &. More...

Classes

struct  FunctorRef0
 
struct  FunctorRef1
 
struct  FunctorRef2
 
struct  nil
 

Detailed Description

An unary functor forwarding to some other TFunctor &.

Most algorithms take functor arguments by value. That's inconvenient if the functor wants to collect and return data. Creating and passing a FunctorRef to the algorithm, may help you out of this.

// Counts invokations of operator().
template<class Tp>
struct Counter : public std::unary_function<Tp, void>
{
void operator()( Tp )
{ ++_value; }
Counter() : _value( 0 ) {}
unsigned _value;
};
std::set<SomeType> c;
Counter<SomeType> counter;
// Invokations of FunctorRef are forwarded to counter:
std::for_each( c.begin, c.end(),
// currently you must specify the
// operator() signature:
functorRef<void,SomeType>(counter)
);
Note
FunctorRef must be able to deduce the signature of TFunctor::operator(). This is currently not automated, so you must specify the operator() signature as template arguments.
The order is <result_type, arg1_type, ...> (this differs from std::, where the result comes last).
Todo:
drop it an use boost::ref