测试functional的bind以及相关功能

注:在VS2010 UPDATE1下测试通过

 /*测试functional的bind以及相关功能*/

 #include <iostream>
#include <functional> using namespace std;
using namespace std::placeholders; int TestAdd(int a, int b)
{
return a+b;
}
bool TestCompare(int a, int b)
{
return a<b;
}
class TestBindClass
{
public:
bool operator() (const int &a, const int &b) const
{
cout << a << "<" << b << " ? " << ( a<b ? "true" : "false" ) << endl;
return a<b;
}
typedef int first_argument_type;
typedef int second_argument_type;
typedef bool result_type;
};
template <class T> struct greater1
{
bool operator() (const T& x, const T& y) const
{
cout << x << ">" << y << " ? " << ( x>y ? "true" : "false" ) << endl;
return x>y;
}
//void operator() (const T& a, const T& b) const {cout << "a<b ? " << ( a<b ? "true" : "false" ) << endl;}
typedef T first_argument_type;
typedef T second_argument_type;
typedef bool result_type;
}; void main()
{
//test bind function
auto fcn1 = bind(TestAdd, , );
cout << fcn1() << endl; //test bind function
auto fcn2 = bind(TestCompare, _1, );
cout << fcn2() << endl; //test binder1st function
binder1st<greater1<int>> fcn4(greater1<int>(), );
cout << fcn4() << endl; //test binder1st function
binder1st<TestBindClass> fcn3(TestBindClass(), );
cout << fcn3() << endl;
}
上一篇:JSP连接mysql 驱动包


下一篇:IntelliJ IDEA 2016.1.3激活【亲测可用】