I have the piece of code
My doubt is why we can only use functor and not predicate function.Code:#include<iostream> #include<set> using namespace std; class Test { public: int val; }; class comp { bool operator()(Test a, Test b) { return a.val < b.val; } }; bool cmp(Test a, Test b) { return a.val<b.val; } int main() { set<Test,comp>s; return 0; } It comiles fine but int main() { set<Test,cmp>s; return 0; } gives following error setTest.cpp: In function ‘int main()’: setTest.cpp:26: error: type/value mismatch at argument 2 in template parameter list for ‘template<class _Key, class _Compare, class _Alloc> class std::set’ setTest.cpp:26: error: expected a type, got ‘cmp’ setTest.cpp:26: error: invalid type in declaration before ‘;’ token
because in algorithms we can use both functor and predicate.
help me understanding it..




Reply With Quote