STL 清除模板容器 clear.h

#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


版权声明:本文博主原创文章,博客,未经同意不得转载。

原文地址:https://www.cnblogs.com/zfyouxi/p/4842495.html