| 发表于:2007-09-20 20:41:352楼 得分:0 |
#include <iostream> #include <vector> #include <algorithm> using namespace std; template <class _t,class _res=bool > struct mybeetwen { typedef _res restype; typedef _t first_arg1; _res operator ()(const _t &x ,const _t&a,const _t&b) { return (x> =a) && (x <=b) ; } }; template <class operation,class t> class mybinder3 { public: typedef typename operation::restype res; typedef typename operation::first_arg1 arg1; explicit mybinder3(operation opx,t x,t y):op(opx),a(x),b(y) {} res operator ()(const arg1& data) {return op(data,a,b); } private: t a,b; operation op; }; template <class operator,class t> inline mybinder3 <operator,t> mybind3 (operator x,t a,t b) { return mybinder3 <operator,t> (x,a,b ); } int main() { vector <int> v; v.push_back(10);v.push_back(15);v.push_back(19);v.push_back(20);v.push_back(14); int count=count_if( v.begin(),v.end(), mybind3( mybeetwen <int,bool> (),10,20) ); cout < <count; } | | |
|