这里主要是介绍一个常用的指针删除器的使用,主要是为了便于前文中smart_ptr(请参考:
http://blog.csdn.net/hello_wyq/archive/2006/07/07/888703.aspx)的使用,希望能够网友一些启发,便于日后的交流和跟进。
// Author : Wang yanqing
// Module : Smart pointer
// Version : 0.01
// Date : 03-Aug-2005
// Reversion:
// Date :
// EMail : hello.wyq@gmail.com
#ifndef _SMART_PTR_DELETER_H
#define _SMART_PTR_DELETER_H
#include <functional>
#include <assert.h>
#include <malloc.h>
#define SMART_PTR_DELETER_CHECK( T, pt ) /
do { /
assert( pt != NULL ); /
typedef char IsTypeValid[ sizeof( T ) ? 1 : -1 ]; /
(void) sizeof( IsTypeValid ); /
} while ( 0 )
template <typename T>
struct SmartPtrDeleter : public std::unary_function<T, void>
{
inline void operator ()( const T *pt ) const
{
SMART_PTR_DELETER_CHECK( T, pt );
delete pt;
}
};
template <typename T>
struct SmartPtrArrayDeleter : public std::unary_function<T, void>
{
inline void operator ()( const T *pt ) const
{
SMART_PTR_DELETER_CHECK( T, pt );
delete[] pt;
}
};
template <typename T>
struct SmartPtrDeafDeleter : public std::unary_function<T, void>
{
inline void operator ()( const T *pt ) const
{
SMART_PTR_DELETER_CHECK( T, pt );
}
};
template <typename T>
struct SmartPtrCDeleter : public std::unary_function<T, void>
{
inline void operator ()( T *pt ) const
{
SMART_PTR_DELETER_CHECK( T, pt );
free( pt );
}
};
#endif