12 #ifndef ROC_CORE_SCOPED_PTR_H_
13 #define ROC_CORE_SCOPED_PTR_H_
32 template <
class T,
class AllocationPolicy = ArenaAllocation>
43 policy_.reset(
new (policy_) AllocationPolicy(policy));
54 policy_->destroy(*ptr_);
61 void reset(T* new_ptr,
const AllocationPolicy& new_policy) {
62 if (new_ptr != ptr_) {
66 policy_.reset(
new (policy_) AllocationPolicy(new_policy));
74 roc_panic(
"scoped ptr: attempting to release a null pointer");
96 roc_panic(
"scoped ptr: attempting to dereference a null pointer");
102 operator const struct unspecified_bool *()
const {
103 return (unspecified_bool*)ptr_;
Base class for non-copyable objects.
Optionally constructed object.
T * operator->() const
Get underlying pointer.
void reset(T *new_ptr, const AllocationPolicy &new_policy)
Reset pointer to a new value.
T * release()
Get underlying pointer and pass ownership to the caller.
void reset()
Reset pointer to null.
T & operator*() const
Get underlying reference.
ScopedPtr(T *ptr, const AllocationPolicy &policy)
Initialize from a raw pointer.
~ScopedPtr()
Destroy object.
ScopedPtr()
Initialize null pointer.
T * get() const
Get underlying pointer.
Optionally constructed object.
#define roc_panic(...)
Print error message and terminate program gracefully.
Commonly used types and functions.