#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
//适配器模式就是将已经写好的接口,但是这个接口不符合要求
struct MyPrint {
void operator()(int v1, int v2) {
cout << v1 + v2 << endl;
}
};
//定义一个目标接口
class Target {
public:
virtual void operator()(int v) = 0;
};
//写适配器
class Adapter:public Target
{
public:
Adapter(int param) {
this->m_param = param;
}
virtual void operator()(int v) {
print(v, 100);
}
private:
MyPrint print;
int m_param;
};
//MyBind2nd
Adapter MyBind2nd(int v)
{
return Adapter(v);
}
int main()
{
vector<int> v;
for (auto i = 0; i < 10; ++i)
{
v.push_back(i);
}
for_each(v.begin(), v.end(), MyBind2nd(100));
system("pause");
return 0;
}