|
|
@ -31,7 +31,8 @@
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef _BOX_CPP
|
|
|
|
#ifdef _BOX_CPP
|
|
|
|
#warning "Using BOX with non-POD types is discouraged"
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#error "Using BOX with non-POD types causes memory leaks"
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstdlib>
|
|
|
@ -52,11 +53,23 @@ inline T* box()
|
|
|
|
return (T*)ptr;
|
|
|
|
return (T*)ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef _BOX_CPP
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
|
|
|
inline T* box(T&& val)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return new T(std::move(val));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
template<typename T>
|
|
|
|
inline T* box(T val)
|
|
|
|
inline T* box(T val)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef _BOX_CPP
|
|
|
|
|
|
|
|
T* ptr = new T(std::move(val));
|
|
|
|
|
|
|
|
#else
|
|
|
|
T* ptr = box<T>();
|
|
|
|
T* ptr = box<T>();
|
|
|
|
*ptr = val;
|
|
|
|
*ptr = val;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
return ptr;
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|