功能描述:
搬运容器到另一个容器中
函数原型:
- transform(iterator beg1, iterator end1, iterator beg2, _func); `
- beg1 源容器开始迭代器
- end1 源容器结束迭代器
- beg2 目标容器开始迭代器
- _func 函数或者函数对象
#include"transform.h"
class Transform
{
public:
int operator()(int val)
{
return val;
}
};
class MyPrint
{
public:
void operator()(int val)
{
cout << val << ",";
}
};
void transform()
{
vector<int> arr_01;
for (int i = 0; i < 10; i++)
{
arr_01.push_back(i);
}
for_each(arr_01.begin(), arr_01.end(), MyPrint());
cout << endl;
vector<int> arr_02;
arr_02.resize(arr_01.size());
transform(arr_01.begin(), arr_01.end(), arr_02.begin(), Transform());
cout << endl;
for_each(arr_02.begin(),arr_02.end(), MyPrint());
cout << endl;
}