您的位置:首页 > 其它

STL 清除模板容器 clear.h

2015-09-27 18:06 281 查看
#pragma once
#include "GeometricMacro.h"
#include "GeometricEnum.h"
#include "McGePoint2d.h"

_GEOMETRIC_BEGIN

template<class T>  inline bool clearvct(std::vector<T*>& vctVal)
{
for(std::vector<T*>::iterator p=vctVal.begin();p!=vctVal.end();++p)
{
delete static_cast<T*>(*p);
*p=NULL;
}
vctVal.clear();
return true;
}

template<class T>  inline bool clearlst(std::list<T*>& lstVal)
{
for(std::list<T*>::iterator p=lstVal.begin();p!=lstVal.end();++p)
{
delete static_cast<T*>(*p);
*p=NULL;
}
lstVal.clear();
return true;
}

template<class T1,class T2>  inline bool clearmap(std::map<T1,T2*>& mapVal)
{
for(std::map<T1,T2*>::iterator p=mapVal.begin();p!=mapVal.end();++p)
{
delete static_cast<T2*>(p->second);
static_cast<T2*>(p->second)=NULL;
}
mapVal.clear();
return true;
}

_GEOMETRIC_END



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: