transform函数原型

1.

template<class _InIt,
class _OutIt,
class _Fn1> inline
_OutIt transform(_InIt _First, _InIt _Last,
_OutIt _Dest, _Fn1 _Func)
{ // transform [_First, _Last) with _Func
_DEPRECATE_UNCHECKED(transform, _Dest);
return (_Transform_no_deprecate(_First, _Last, _Dest, _Func));
}

2.

template<class _InIt1,
class _InIt2,
class _OutIt,
class _Fn2> inline
_OutIt transform(_InIt1 _First1, _InIt1 _Last1,
_InIt2 _First2, _OutIt _Dest, _Fn2 _Func)
{ // transform [_First1, _Last1) and [_First2, ...) with _Func
_DEFINE_DEPRECATE_UNCHECKED(transform);
_USE_DEPRECATE_UNCHECKED(_First2);
_USE_DEPRECATE_UNCHECKED(_Dest);
return (_Transform_no_deprecate(_First1, _Last1, _First2, _Dest, _Func));
}

3.

 #if _ITERATOR_DEBUG_ARRAY_OVERLOADS
template<class _InIt,
class _OutTy,
size_t _OutSize,
class _Fn1> inline
_OutTy *transform(_InIt _First, _InIt _Last,
_OutTy (&_Dest)[_OutSize], _Fn1 _Func)
{ // transform [_First, _Last) with _Func, array dest
return (_Unchecked(
_Transform_no_deprecate(_First, _Last,
_Array_iterator<_OutTy, _OutSize>(_Dest), _Func)));
}
#endif /* _ITERATOR_DEBUG_ARRAY_OVERLOADS */

4-6.

 #if _ITERATOR_DEBUG_ARRAY_OVERLOADS
template<class _InIt1,
class _InTy,
size_t _InSize,
class _OutIt,
class _Fn2> inline
_OutIt transform(_InIt1 _First1, _InIt1 _Last1,
_InTy (&_First2)[_InSize], _OutIt _Dest, _Fn2 _Func)
{ // transform [_First1, _Last1) and [_First2, ...), array input
_DEPRECATE_UNCHECKED(transform, _Dest);
return (_Transform_no_deprecate(_First1, _Last1,
_Array_iterator<_InTy, _InSize>(_First2), _Dest, _Func));
} template<class _InIt1,
class _InIt2,
class _OutTy,
size_t _OutSize,
class _Fn2> inline
_OutTy *transform(_InIt1 _First1, _InIt1 _Last1,
_InIt2 _First2, _OutTy (&_Dest)[_OutSize], _Fn2 _Func)
{ // transform [_First1, _Last1) and [_First2, ...), array dest
_DEPRECATE_UNCHECKED(transform, _First2);
return (_Unchecked(
_Transform_no_deprecate(_First1, _Last1,
_First2, _Array_iterator<_OutTy, _OutSize>(_Dest), _Func)));
} template<class _InIt1,
class _InTy,
size_t _InSize,
class _OutTy,
size_t _OutSize,
class _Fn2> inline
_OutTy *transform(_InIt1 _First1, _InIt1 _Last1,
_InTy (&_First2)[_InSize], _OutTy (&_Dest)[_OutSize], _Fn2 _Func)
{ // transform [_First1, _Last1) and [_First2, ...), array input/dest
return (_Unchecked(
_Transform_no_deprecate(_First1, _Last1,
_Array_iterator<_InTy, _InSize>(_First2),
_Array_iterator<_OutTy, _OutSize>(_Dest), _Func)));
}
#endif /* _ITERATOR_DEBUG_ARRAY_OVERLOADS */

暂时只研究前面2种

1.

#include <iostream>
#include<algorithm>
#include <functional>
#include <vector> using namespace std;
class Ticket
{
public:
Ticket()
{
;
}
int num;
int id;
char zimu;
};
class MyShow_transform
{
public:
Ticket* operator()(Ticket* t)
{
if (t->zimu == 'A')
{
cout << "车号:" << t->num << "座位:" << t->id << "排" << t->zimu << "座" << endl;
return t;
}
t->num = 0;
return t;
}
};
void show(Ticket* t)
{
if(t->num != 0)
cout<< t->num << "车" << t->id << "排" << t->zimu << "座" << endl;
return;
}
void test_transform()
{
vector<Ticket*> v1,v2,v3; for (int num = 0; num < 2; num++)
{
for (int id = 0; id < 5; id++)
{
for (int i = 0; i < 5; i++)
{
Ticket *tmp = new Ticket;
tmp->num = num+1;
tmp->id = id+1;
tmp->zimu = 'A' + i;
v1.push_back(tmp);
}
}
}
v2.resize(v1.size());
transform(v1.begin(), v1.end(), v2.begin(),MyShow_transform() );
cout << "-------------------------------------------------------------------" << endl;
for_each(v2.begin(), v2.end(), show);
for (vector<Ticket*>::iterator it = v1.begin(); it != v1.end(); )
{
delete (*it);
it = v1.erase(it);
it++;
}
}

增加函数适配器

#include <iostream>
#include<algorithm>
#include <functional>
#include <vector> using namespace std;
class Ticket
{
public:
Ticket()
{
;
}
int num;
int id;
char zimu;
};
class MyShow_transform : public std::binary_function<Ticket*, char, Ticket*>
{
public:
Ticket* operator()(const Ticket* t, const char c)const
{
Ticket* p = nullptr;
if (t->zimu == c)
{
cout << "车号:" << t->num << "座位:" << t->id << "排" << t->zimu << "座" << endl;
p = const_cast<Ticket *>(t);
return p;
}
if(p != nullptr)
p->num = 0;
return p;
}
};
void show(Ticket* t)
{
if (t == nullptr)
return;
if(t->num != 0)
cout<< t->num << "车" << t->id << "排" << t->zimu << "座" << endl;
return;
}
void test_transform()
{
vector<Ticket*> v1,v2,v3; for (int num = 0; num < 2; num++)
{
for (int id = 0; id < 5; id++)
{
for (int i = 0; i < 5; i++)
{
Ticket *tmp = new Ticket;
tmp->num = num+1;
tmp->id = id+1;
tmp->zimu = 'A' + i;
v1.push_back(tmp);
}
}
}
v2.resize(v1.size());
transform(v1.begin(), v1.end(), v2.begin(),bind2nd( MyShow_transform(),'A' ));
cout << "-------------------------------------------------------------------" << endl;
for_each(v2.begin(), v2.end(), show);
for (vector<Ticket*>::iterator it = v1.begin(); it != v1.end(); )
{
delete (*it);
it = v1.erase(it);
it++;
}
} void main()
{
test_transform();
cout << endl;
cout << "hello" << endl;
system("pause");
}

  

2.增加一个vector

#include <iostream>
#include<algorithm>
#include <functional>
#include <vector> using namespace std;
class Ticket
{
public:
Ticket()
{
;
}
int num;
int id;
char zimu;
};
class MyShow_transform : public std::binary_function<Ticket*, char, Ticket*>
{
public:
Ticket* operator()(const Ticket* t, const char c)const
{
Ticket* p = nullptr;
if (t->zimu == c)
{
cout << "车号:" << t->num << "座位:" << t->id << "排" << t->zimu << "座" << endl;
p = const_cast<Ticket *>(t);
return p;
}
if(p != nullptr)
p->num = 0;
return p;
}
};
class MyShow_transformadv : public std::binary_function<Ticket*, Ticket*, Ticket*>
{
public:
Ticket* operator()(const Ticket* t1, const Ticket* t2)const
{
Ticket* p = nullptr;
p = const_cast<Ticket *>(t1);
if (t2 == nullptr)
return p;
if (t1->num == t2->num)
{
cout << "车号:" << t1->num << "座位:" << t1->id << "排" << t1->zimu << "座" << endl;
return p;
}
if (p != nullptr)
p->num = 0;
return p;
}
};
void show(Ticket* t)
{
if (t == nullptr)
return;
if(t->num != 0)
cout<< t->num << "车" << t->id << "排" << t->zimu << "座" << endl;
return;
}
void test_transform()
{
vector<Ticket*> v1,v2,v3; for (int num = 0; num < 2; num++)
{
for (int id = 0; id < 5; id++)
{
for (int i = 0; i < 5; i++)
{
Ticket *tmp = new Ticket;
tmp->num = num+1;
tmp->id = id+1;
tmp->zimu = 'A' + i;
v1.push_back(tmp);
}
}
}
v2.resize(v1.size());
cout << "v2-------------------------------------------------------------------" << endl;
transform(v1.begin(), v1.end(), v2.begin(),bind2nd( MyShow_transform(),'A' ));
v3.resize(v1.size());
cout << "v3-------------------------------------------------------------------" << endl;
transform(v1.begin(), v1.end(), v2.begin(),v3.begin(), MyShow_transformadv());
cout << "-------------------------------------------------------------------" << endl; for (vector<Ticket*>::iterator it = v1.begin(); it != v1.end(); )
{
delete (*it);
it = v1.erase(it);
it++;
}
} void main()
{
test_transform();
cout << endl;
cout << "hello" << endl;
system("pause");
}

最新文章

  1. Quartz —— 从 HelloWorld 开始
  2. 64位系统装oracle(ora-12154 )
  3. 清空StringBuilder的三种方法及效率
  4. ASP.net的url重写
  5. 如何打印出lua里table的内容
  6. 对于PKI(公钥基础结构)及证书服务的通俗理解
  7. cocos2dx Hello world 创建
  8. python 通过ntlm验证下载文件
  9. sharpSVN说明文档
  10. Graph(Floyd)
  11. DFS算法(——模板习题与总结)
  12. PTA变成总结1
  13. 数据库事务的四大特性以及事务的隔离级别-与-Spring事务传播机制&amp;隔离级别
  14. Windows登录类型及安全日志解析
  15. C#_XML与Object转换
  16. 大数据系列博客之 --- 深入简出 Shell 脚本语言(高级篇)
  17. amcharts去除版权标志
  18. 虚拟机centos NAT模式 配置静态ip
  19. warning:ISO C90 forbids mixed declarations and code
  20. URAL 1969. Hong Kong Tram

热门文章

  1. URL的组成格式
  2. About SQLite
  3. powerdesinger
  4. Linux常用调优配置
  5. asp.net项目在IE11下出现“__doPostBack”未定义的解决办法
  6. hibernate---CRUD
  7. 前端性能优化(三)——传统 JavaScript 优化的误区
  8. C++程序设计实践指导1.13自然数集中找合数改写要求实现
  9. Mysql5.7服务下载安装
  10. JXL组件生成报表报错(一)
  11. JavaEE介绍
  12. Vue-cli的配置知识
  13. pytorch识别CIFAR10:训练ResNet-34(自定义transform,动态调整学习率,准确率提升到94.33%)
  14. Typora使用说明(记录总结)
  15. 深入理解泛型之JAVA泛型的继承和实现、泛型擦除
  16. 前向传播算法(Forward propagation)与反向传播算法(Back propagation)
  17. Maven学习第2期---Maven安装配置
  18. Android自定义控件三种方式
  19. datatables日常使用集合
  20. zabbix使用自定义脚本监控内存