#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
// unary functor; performs '&&'
template <typename T>
struct AND
{
function<bool (const T&)> x;
function<bool (const T&)> y;
AND(function<bool (const T&)> xx, function<bool (const T&)> yy)
: x(xx), y(yy) {}
bool operator() ( const T &arg ) { return x(arg) && y(arg); }
};
// helper
template <typename T>
AND<T> And(function<bool (const T&)> xx, function<bool (const T&)> yy)
{
return AND<T>(xx,yy);
}
bool is_odd(int n) { return n%2; }
bool is_big(int n) { return n>5; }
bool big_odd_exists( vector<int>::iterator first, vector<int>::iterator last )
{
/*
function<bool (const int &)> fun1 = is_odd;
function<bool (const int &)> fun2 = is_big;
*/
//return any_of( first, last, And( fun1, fun2 ) ); // instantiating an And object
return any_of( first, last, And<int>( is_odd, is_big ) );
}
int main()
{
std::vector<int> n = {1, 3, 5, 7, 9, 10, 11};
cout << "exists : " << big_odd_exists( n.begin(), n.end() ) << endl;
}
I2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGZ1bmN0aW9uYWw+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHZlY3Rvcj4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgovLyB1bmFyeSBmdW5jdG9yOyBwZXJmb3JtcyAnJiYnCnRlbXBsYXRlIDx0eXBlbmFtZSBUPgpzdHJ1Y3QgQU5ECnsKICAgIGZ1bmN0aW9uPGJvb2wgKGNvbnN0IFQmKT4geDsKICAgIGZ1bmN0aW9uPGJvb2wgKGNvbnN0IFQmKT4geTsKCiAgICBBTkQoZnVuY3Rpb248Ym9vbCAoY29uc3QgVCYpPiB4eCwgZnVuY3Rpb248Ym9vbCAoY29uc3QgVCYpPiB5eSkgCiAgICAgICAgICAgICA6IHgoeHgpLCB5KHl5KSB7fQogICAgYm9vbCBvcGVyYXRvcigpICggY29uc3QgVCAmYXJnICkgeyByZXR1cm4geChhcmcpICYmIHkoYXJnKTsgfQp9OwoKLy8gaGVscGVyCnRlbX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