I came across the following find_if function.
find_if (coll.begin(), coll.end(),
bind(logical_and<bool>(),
bind(greater<int>(),_1,x), bind(less<int>(),_1,y)
)
);
I've the doubt that how the bind(greater(),_1,x) and bind(less(),_1,y) are evaluated and returning bool values there? This will not work otherwise as shown below.
#include <iostream>
#include <functional>
int main()
{
using namespace std::placeholders;
//auto fn = std::bind(std::greater<int>(), 5, _1);
//std::cout << fn(7) << std::endl;
//std::cout << typeid(fn).name() << std::endl;
auto fn1 = std::bind(std::greater<int>(),5,6);
auto fn2 = std::bind(std::less<int>(),7,5);
std::cout << std::bind( std::logical_and<bool>(), fn1, fn2 )(); // how this works??
std::cout << std::logical_and<bool>()(fn1, fn2)(); // Compilation error
}
Really curious to know how the functors are called inside the bind function. Can someone please explain how this works? Thanks in advance.