#define _CRT_SECURE_NO_WARNINGS h
#include<iostream>
#include<algorithm>
using namespace std;
//class Person
//{
//public:
//
// //Person() = delete;
// Person(Person&& p) = delete;
//private:
// string _name;
// int _age;
//};
//
//int main()
//{
// Person p1;
// Person p2=p1;
// Person p3=move(p1);
//
// return 0;
//}
//class animal
//{
//public:
// virtual void say()
// {
// cout << "各种各样的声音" << endl;
// }
//};
//
//class dog :public animal
//{
//public:
// virtual void say() override
// {
// cout << "芝士小狗" << endl;
// }
//};
#include<functional>
int sub(int a, int b)
{
return a - b;
}
int threesub(int a,int b,int c)
{
return a - b - c;
}
struct Functor
{
public:
int operator() (int a, int b)
{
return a + b;
}
};
class Plus
{
public:
Plus(int n = 10)
:_n(n)
{}
static int plusi(int a, int b)
{
return a + b;
}
double plusd(double a, double b)
{
return (a + b) * _n;
}
private:
int _n;
};
void Print()
{
cout << "hello world" << endl;
}
using placeholders::_1;
using placeholders::_2;
using placeholders::_3;
int main()
{
//auto b1 = bind(sub, _1, _2);
//cout << b1(3, 1) << endl;
bind本质上返回一个仿函数对象
调整参数顺序0
_1代表第一个实参
_2代表第二个实参
//auto b2 = bind(sub, _2, _1);
//cout << b2(3, 1) << endl;
//auto b3 = bind(sub, 100, _1);
//cout << b3(10) << endl;
//auto b4 = bind(sub, _1, 100);
//cout << b4(10) << endl;
//auto b5 = bind(threesub, _1, _2, 100);
//cout << b5(5, 1) << endl;
//auto b6 = bind(threesub,100, _1, _2);
//cout << b6(5, 1) << endl;
//auto b7 = bind(threesub, _1, 100, _2);
//cout << b7(5, 1) << endl;
成员函数对象进行绑死,就不需要每次都传递了
//function<double(Plus&&, double, double)> ff1 = &Plus::plusd;
//Plus p;
//cout << ff1(move(p), 1.1, 1.1) << endl;
//cout << ff1(Plus(), 1.1, 1.1) << endl;
//function<double(double, double)> ff2 = bind(&Plus::plusd, Plus(), _1, _2);
//cout << ff2(1.1, 1.1) << endl;
auto func1 = [](double rate, double money, int year) {
double ret = money;
for (int i = 0; i < year; i++)
{
ret += ret * rate;
}
return ret - money;
};
// 绑死⼀些参数,实现出⽀持不同年华利率,不同⾦额和不同年份计算出复利的结算利息
function<double(double)> func3_1_5 = bind(func1, 0.015, _1, 3);
function<double(double)> func5_1_5 = bind(func1, 0.015, _1, 5);
function<double(double)> func10_2_5 = bind(func1, 0.025, _1, 10);
function<double(double)> func20_3_5 = bind(func1, 0.035, _1, 30);
cout << func3_1_5(1000000) << endl;
cout << func5_1_5(1000000) << endl;
cout << func10_2_5(1000000) << endl;
cout << func20_3_5(1000000) << endl;
}
//int main()
//{
// //function<int(int, int)> f1 = add;
// //function<int(int, int)> f2 = Functor();
// //function<int(int, int)> f3 = [](int a, int b) {return a + b; };
// //function<void()> f4 = Print;
// //f4();
//
// //cout << f1(1, 1)<<endl;
// //cout << f2(1, 1)<<endl;
// //cout << f3(1, 1)<<endl;
//
// //包装静态成员函数
// //成员函数要指定类域并且前面加&才能获取地址
// function<int(int, int)> f5 = &Plus::plusi;
// cout << f5(1, 1) << endl;
//
// //包装不同成员函数
// //普通成员函数还有一个隐含的this指针参数,所以绑定时传对象或者对象的指针过去都可以
// Plus p;
// function<double(Plus*, double, double)> f6 = &Plus::plusd;
// cout << f6(&p, 2.2, 2.2) << endl;
//
// function<double(Plus, double, double)> f7 = &Plus::plusd;
// cout << f7(p, 2.2, 2.2) << endl;
//
// function<double(Plus&&, double, double)> f8 = &Plus::plusd;
// cout << f8(move(p), 2.2, 2.2) << endl;
//
// return 0;
//}
#define _CRT_SECURE_NO_WARNINGS h
#include<iostream>
#include<algorithm>
using namespace std;
//class Person
//{
//public:
//
// //Person() = delete;
// Person(Person&& p) = delete;
//private:
// string _name;
// int _age;
//};
//
//int main()
//{
// Person p1;
// Person p2=p1;
// Person p3=move(p1);
//
// return 0;
//}
//class animal
//{
//public:
// virtual void say()
// {
// cout << "各种各样的声音" << endl;
// }
//};
//
//class dog :public animal
//{
//public:
// virtual void say() override
// {
// cout << "芝士小狗" << endl;
// }
//};
#include<functional>
int sub(int a, int b)
{
return a - b;
}
int threesub(int a,int b,int c)
{
return a - b - c;
}
struct Functor
{
public:
int operator() (int a, int b)
{
return a + b;
}
};
class Plus
{
public:
Plus(int n = 10)
:_n(n)
{}
static int plusi(int a, int b)
{
return a + b;
}
double plusd(double a, double b)
{
return (a + b) * _n;
}
private:
int _n;
};
void Print()
{
cout << "hello world" << endl;
}
using placeholders::_1;
using placeholders::_2;
using placeholders::_3;
int main()
{
//auto b1 = bind(sub, _1, _2);
//cout << b1(3, 1) << endl;
bind本质上返回一个仿函数对象
调整参数顺序0
_1代表第一个实参
_2代表第二个实参
//auto b2 = bind(sub, _2, _1);
//cout << b2(3, 1) << endl;
//auto b3 = bind(sub, 100, _1);
//cout << b3(10) << endl;
//auto b4 = bind(sub, _1, 100);
//cout << b4(10) << endl;
//auto b5 = bind(threesub, _1, _2, 100);
//cout << b5(5, 1) << endl;
//auto b6 = bind(threesub,100, _1, _2);
//cout << b6(5, 1) << endl;
//auto b7 = bind(threesub, _1, 100, _2);
//cout << b7(5, 1) << endl;
成员函数对象进行绑死,就不需要每次都传递了
//function<double(Plus&&, double, double)> ff1 = &Plus::plusd;
//Plus p;
//cout << ff1(move(p), 1.1, 1.1) << endl;
//cout << ff1(Plus(), 1.1, 1.1) << endl;
//function<double(double, double)> ff2 = bind(&Plus::plusd, Plus(), _1, _2);
//cout << ff2(1.1, 1.1) << endl;
auto func1 = [](double rate, double money, int year) {
double ret = money;
for (int i = 0; i < year; i++)
{
ret += ret * rate;
}
return ret - money;
};
// 绑死⼀些参数,实现出⽀持不同年华利率,不同⾦额和不同年份计算出复利的结算利息
function<double(double)> func3_1_5 = bind(func1, 0.015, _1, 3);
function<double(double)> func5_1_5 = bind(func1, 0.015, _1, 5);
function<double(double)> func10_2_5 = bind(func1, 0.025, _1, 10);
function<double(double)> func20_3_5 = bind(func1, 0.035, _1, 30);
cout << func3_1_5(1000000) << endl;
cout << func5_1_5(1000000) << endl;
cout << func10_2_5(1000000) << endl;
cout << func20_3_5(1000000) << endl;
}
//int main()
//{
// //function<int(int, int)> f1 = add;
// //function<int(int, int)> f2 = Functor();
// //function<int(int, int)> f3 = [](int a, int b) {return a + b; };
// //function<void()> f4 = Print;
// //f4();
//
// //cout << f1(1, 1)<<endl;
// //cout << f2(1, 1)<<endl;
// //cout << f3(1, 1)<<endl;
//
// //包装静态成员函数
// //成员函数要指定类域并且前面加&才能获取地址
// function<int(int, int)> f5 = &Plus::plusi;
// cout << f5(1, 1) << endl;
//
// //包装不同成员函数
// //普通成员函数还有一个隐含的this指针参数,所以绑定时传对象或者对象的指针过去都可以
// Plus p;
// function<double(Plus*, double, double)> f6 = &Plus::plusd;
// cout << f6(&p, 2.2, 2.2) << endl;
//
// function<double(Plus, double, double)> f7 = &Plus::plusd;
// cout << f7(p, 2.2, 2.2) << endl;
//
// function<double(Plus&&, double, double)> f8 = &Plus::plusd;
// cout << f8(move(p), 2.2, 2.2) << endl;
//
// return 0;
//}
#define _CRT_SECURE_NO_WARNINGS h
#include<iostream>
#include<algorithm>
using namespace std;
//class Person
//{
//public:
//
// //Person() = delete;
// Person(Person&& p) = delete;
//private:
// string _name;
// int _age;
//};
//
//int main()
//{
// Person p1;
// Person p2=p1;
// Person p3=move(p1);
//
// return 0;
//}
//class animal
//{
//public:
// virtual void say()
// {
// cout << "各种各样的声音" << endl;
// }
//};
//
//class dog :public animal
//{
//public:
// virtual void say() override
// {
// cout << "芝士小狗" << endl;
// }
//};
#include<functional>
int sub(int a, int b)
{
return a - b;
}
int threesub(int a,int b,int c)
{
return a - b - c;
}
struct Functor
{
public:
int operator() (int a, int b)
{
return a + b;
}
};
class Plus
{
public:
Plus(int n = 10)
:_n(n)
{}
static int plusi(int a, int b)
{
return a + b;
}
double plusd(double a, double b)
{
return (a + b) * _n;
}
private:
int _n;
};
void Print()
{
cout << "hello world" << endl;
}
using placeholders::_1;
using placeholders::_2;
using placeholders::_3;
int main()
{
//auto b1 = bind(sub, _1, _2);
//cout << b1(3, 1) << endl;
bind本质上返回一个仿函数对象
调整参数顺序0
_1代表第一个实参
_2代表第二个实参
//auto b2 = bind(sub, _2, _1);
//cout << b2(3, 1) << endl;
//auto b3 = bind(sub, 100, _1);
//cout << b3(10) << endl;
//auto b4 = bind(sub, _1, 100);
//cout << b4(10) << endl;
//auto b5 = bind(threesub, _1, _2, 100);
//cout << b5(5, 1) << endl;
//auto b6 = bind(threesub,100, _1, _2);
//cout << b6(5, 1) << endl;
//auto b7 = bind(threesub, _1, 100, _2);
//cout << b7(5, 1) << endl;
成员函数对象进行绑死,就不需要每次都传递了
//function<double(Plus&&, double, double)> ff1 = &Plus::plusd;
//Plus p;
//cout << ff1(move(p), 1.1, 1.1) << endl;
//cout << ff1(Plus(), 1.1, 1.1) << endl;
//function<double(double, double)> ff2 = bind(&Plus::plusd, Plus(), _1, _2);
//cout << ff2(1.1, 1.1) << endl;
auto func1 = [](double rate, double money, int year) {
double ret = money;
for (int i = 0; i < year; i++)
{
ret += ret * rate;
}
return ret - money;
};
// 绑死⼀些参数,实现出⽀持不同年华利率,不同⾦额和不同年份计算出复利的结算利息
function<double(double)> func3_1_5 = bind(func1, 0.015, _1, 3);
function<double(double)> func5_1_5 = bind(func1, 0.015, _1, 5);
function<double(double)> func10_2_5 = bind(func1, 0.025, _1, 10);
function<double(double)> func20_3_5 = bind(func1, 0.035, _1, 30);
cout << func3_1_5(1000000) << endl;
cout << func5_1_5(1000000) << endl;
cout << func10_2_5(1000000) << endl;
cout << func20_3_5(1000000) << endl;
}
//int main()
//{
// //function<int(int, int)> f1 = add;
// //function<int(int, int)> f2 = Functor();
// //function<int(int, int)> f3 = [](int a, int b) {return a + b; };
// //function<void()> f4 = Print;
// //f4();
//
// //cout << f1(1, 1)<<endl;
// //cout << f2(1, 1)<<endl;
// //cout << f3(1, 1)<<endl;
//
// //包装静态成员函数
// //成员函数要指定类域并且前面加&才能获取地址
// function<int(int, int)> f5 = &Plus::plusi;
// cout << f5(1, 1) << endl;
//
// //包装不同成员函数
// //普通成员函数还有一个隐含的this指针参数,所以绑定时传对象或者对象的指针过去都可以
// Plus p;
// function<double(Plus*, double, double)> f6 = &Plus::plusd;
// cout << f6(&p, 2.2, 2.2) << endl;
//
// function<double(Plus, double, double)> f7 = &Plus::plusd;
// cout << f7(p, 2.2, 2.2) << endl;
//
// function<double(Plus&&, double, double)> f8 = &Plus::plusd;
// cout << f8(move(p), 2.2, 2.2) << endl;
//
// return 0;
//}