标签:str ... nullptr last 一个 fun debug NPU resize
transform函数原型
1.
template 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 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 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 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 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 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
#include
#include
#include
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 num id zimu num = 0;
return t;
}
};
void show(Ticket* t)
{
if(t->num != 0)
coutnum id zimu v1,v2,v3;
for (int num = 0; num 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 ::iterator it = v1.begin(); it != v1.end(); )
{
delete (*it);
it = v1.erase(it);
it++;
}
}
增加函数适配器
#include
#include
#include
#include
using namespace std;
class Ticket
{
public:
Ticket()
{
;
}
int num;
int id;
char zimu;
};
class MyShow_transform : public std::binary_function
{
public:
Ticket* operator()(const Ticket* t, const char c)const
{
Ticket* p = nullptr;
if (t->zimu == c)
{
cout num id zimu (t);
return p;
}
if(p != nullptr)
p->num = 0;
return p;
}
};
void show(Ticket* t)
{
if (t == nullptr)
return;
if(t->num != 0)
coutnum id zimu v1,v2,v3;
for (int num = 0; num 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 ::iterator it = v1.begin(); it != v1.end(); )
{
delete (*it);
it = v1.erase(it);
it++;
}
}
void main()
{
test_transform();
cout
2.增加一个vector
#include
#include
#include
#include
using namespace std;
class Ticket
{
public:
Ticket()
{
;
}
int num;
int id;
char zimu;
};
class MyShow_transform : public std::binary_function
{
public:
Ticket* operator()(const Ticket* t, const char c)const
{
Ticket* p = nullptr;
if (t->zimu == c)
{
cout num id zimu (t);
return p;
}
if(p != nullptr)
p->num = 0;
return p;
}
};
class MyShow_transformadv : public std::binary_function
{
public:
Ticket* operator()(const Ticket* t1, const Ticket* t2)const
{
Ticket* p = nullptr;
p = const_cast(t1);
if (t2 == nullptr)
return p;
if (t1->num == t2->num)
{
cout num id zimu num = 0;
return p;
}
};
void show(Ticket* t)
{
if (t == nullptr)
return;
if(t->num != 0)
coutnum id zimu v1,v2,v3;
for (int num = 0; num num = num+1;
tmp->id = id+1;
tmp->zimu = ‘A‘ + i;
v1.push_back(tmp);
}
}
}
v2.resize(v1.size());
cout ::iterator it = v1.begin(); it != v1.end(); )
{
delete (*it);
it = v1.erase(it);
it++;
}
}
void main()
{
test_transform();
cout
C++探究transform算法
标签:str ... nullptr last 一个 fun debug NPU resize
原文地址:https://www.cnblogs.com/smh2015/p/9743191.html