首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

哪位高手知道less函数的源代码

2013-07-04 
谁知道less函数的源代码?我尝试写了一下,不行,#include algorithm#include functional#include iostr

谁知道less函数的源代码?
我尝试写了一下,不行,


#include <algorithm>  
#include <functional>  
#include <iostream>  
  
using namespace std;  
template <class T> 
struct F : binary_function <T,T,bool>
{
  bool operator() ( T x, T y)  {return x<y;}
};

int main(int argc,char* argv[])  
{  
    bind1st(F<int>(),1)(2)  ;   
    bind2nd(F<int>(),1)(2) ;   
  
    getchar();  
    return 0;  
}

[解决办法]
template<class _Fn2>
class binder1st
: public unary_function<typename _Fn2::second_argument_type,
typename _Fn2::result_type>
{// functor adapter _Func(stored, right)
public:
typedef unary_function<typename _Fn2::second_argument_type,
typename _Fn2::result_type> _Base;
typedef typename _Base::argument_type argument_type;
typedef typename _Base::result_type result_type;

binder1st(const _Fn2& _Func,
const typename _Fn2::first_argument_type& _Left)
: op(_Func), value(_Left)
{// construct from functor and left operand
}

result_type operator()(const argument_type& _Right) const
{// apply functor to operands
return (op(value, _Right));
}

result_type operator()(argument_type& _Right) const
{// apply functor to operands
return (op(value, _Right));
}

protected:
_Fn2 op;// the functor to apply
typename _Fn2::first_argument_type value;// the left operand
};

_Fn2::first_argument_type
_Fn2::second_argument_type
 _Fn2::result_type
这些不都是么

热点排行