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 have a doubt that how bind (more (), _ 1, x) and bind (less (), _ 1, y) are evaluated and return 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 functors are called inside the bind function. Can someone explain how this works? Thanks in advance.
source share