diff --git a/include/box.h b/include/box.h index c69a6c5..1e25553 100644 --- a/include/box.h +++ b/include/box.h @@ -31,7 +31,8 @@ #ifdef __cplusplus #ifdef _BOX_CPP -#warning "Using BOX with non-POD types is discouraged" +#include +#error "Using BOX with non-POD types causes memory leaks" #endif #include @@ -52,11 +53,23 @@ inline T* box() return (T*)ptr; } +#ifdef _BOX_CPP +template +inline T* box(T&& val) +{ + return new T(std::move(val)); +} +#endif + template inline T* box(T val) { +#ifdef _BOX_CPP + T* ptr = new T(std::move(val)); +#else T* ptr = box(); *ptr = val; +#endif return ptr; }