12#ifndef ROC_CORE_OPTIONAL_H_
13#define ROC_CORE_OPTIONAL_H_
25template <
class T,
size_t Size = sizeof(T)>
class Optional :
public NonCopyable<> {
44 if (ptr && (
void*)ptr != storage_.memory()) {
45 roc_panic(
"optional: attempt to set incorrect object");
58 roc_panic(
"optional: attempt to dereference uninitialized object");
66 roc_panic(
"optional: attempt to dereference uninitialized object");
72 operator const struct unspecified_bool *()
const {
73 return (
const unspecified_bool*)ptr_;
81 roc_panic(
"optional: attempt to get memory after the object was created");
83 return storage_.memory();
97template <
class T,
size_t Size>
100 return opt.unallocated_memory();
106template <
class T,
size_t Size>
Fixed-size maximum-aligned storage.
Optionally constructed object.
T * operator->() const
Get underlying object.
T & operator*() const
Get underlying reference.
T * get() const
Get underlying object.
void reset(T *ptr=NULL)
Set pointer to the newly created object, destroy old pointed object if set.
void * unallocated_memory()
Get object memory.
General-purpose building blocks and platform abstraction layer.
#define roc_panic_if_not(x)
Panic if condition is false.
#define roc_panic(...)
Print error message and terminate program gracefully.
Commonly used types and functions.