#ifndef YHP_CONSTRUCT_H
#define YHP_CONSTRUCT_H
#include"yhp_iterator.h"
#include"yhp_type_traits.h"
namespace yhp
{
template<class T1,class T2>
inline void construct(T1 *p,const T2 &val)
{
new(p) T1(val);
}
template<class T>
inline void construct(T *p)
{
new(p) T();
}
template<class T>
inline void destroy(T *p)
{
p->~T();
}
template<class _FI>
inline void destroy(_FI _F, _FI _L)
{
__destroy(_F,_L,value_type(_F));
}
template<class _FI,class T>
inline void __destroy(_FI _F,_FI _L , T *)
{
__type_traits<T>();
typedef typename __type_traits<T>::has_trivial_destructor dest;
__destroy_aux(_F,_L,dest());
}
template<class _FI>
inline void __destroy_aux(_FI _F,_FI _L , __true_type)
{}
template<class _FI>
inline void __destroy_aux(_FI _F,_FI _L , __false_type)
{
for(; _F != _L; ++_F)
{
destroy(&*_F);
}
}
}
#endif
201-C++construct
最新推荐文章于 2024-02-09 12:50:04 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)