libzypp  13.10.6
zypp::functor::functor_detail Namespace Reference

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

Classes

struct  FunctorRef0
 
struct  FunctorRef1
 
struct  FunctorRef2
 
struct  nil
 

Detailed Description

An unary functor forwarding to some other _Functor &.

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 _Functor::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