return std::weak_ptr<T>(ptr);
}
-namespace detail {
-/**
- * Not all STL implementations define ::free in a way that its address can be
- * determined at compile time. So we must wrap ::free in a function whose
- * address can be determined.
- */
-inline void SysFree(void* p) {
- ::free(p);
-}
-}
+struct SysBufferDeleter {
+ void operator()(void* p) const {
+ ::free(p);
+ }
+};
-using SysBufferDeleter = static_function_deleter<void, &detail::SysFree>;
using SysBufferUniquePtr = std::unique_ptr<void, SysBufferDeleter>;
inline SysBufferUniquePtr allocate_sys_buffer(size_t size) {
return SysBufferUniquePtr(::malloc(size));
public:
void* allocate(size_t size) {
void* p = ::malloc(size);
- if (!p) throw std::bad_alloc();
+ if (!p) {
+ throw std::bad_alloc();
+ }
return p;
}
void deallocate(void* p) {
}
void operator()(pointer p) const {
- if (!p) return;
+ if (!p) {
+ return;
+ }
const_cast<allocator_delete*>(this)->destroy(p);
const_cast<allocator_delete*>(this)->deallocate(p, 1);
}