I am having hard time using variadic template with the following problem.
Suppose that all the predicate functors are of the form,
class Pred1 {
public:
Pred1( Args... ); // The signature Args... can vary class to class.
template <typename T>
bool operator()(T t);
};
Given those functors, I want to make a variadic template class which returns true if all the operator() of each predicate return true, i.e.,
template <typename... Preds>
class CombinePredAnd {
public:
template <typename T>
bool operator()(T t){
// returns true if all of the Preds( Args... ).operator()(t) returns true;
// Args... should be passed when CombinePredAnd is constructed.
}
};
To me, I have no idea to pass arguments to each constructor of Preds.
Could you give me some hint?
Also, if you have better design with the same functionality, please let me know.
Maybe like this:
Usage:
Example:
Note: You could make the “conjunction” part of this approach parametric as well, so you can have conjunctions and disjunctions just by plugging in
std::logical_andorstd::logical_or.