I\'ve written this functor to perform an and operation (&&):
// unary functor; performs \'&&\'
template
I suggest not abusing std::function
and taking normal generic parameters instead. Treat std::function
as a type-erased container for callable objects of a particular signature (see https://stackoverflow.com/a/11629125/46642 for more details).
// unary functor; performs '&&'
template
struct AND
{
X x;
Y y;
template
AND(XX&& xx, YY&& yy)
: x(std::forward(xx)), y(std::forward(yy)) {}
template
auto operator() ( const T &arg ) -> decltype(x(arg) && y(arg))
{ return x(arg) && y(arg); }
};
template
using Decay = typename std::decay::type;
// helper
template
AND, Decay> And(X&& xx, Y&& yy)
{
return AND, Decay>(std::forward(xx), std::forward(yy));
}