22 #ifndef CRNOption_HEADER
23 #define CRNOption_HEADER
37 constexpr
Option() noexcept : var(
nullptr) {}
39 inline Option(
const T &value):var(new T(value)) {}
43 if (o.var) var =
new T(*(o.var));
46 inline Option(
Option &&o) noexcept : var(o.var) { o.var =
nullptr; }
50 if (&o ==
this)
return *
this;
53 if (var) *var = *(o.var);
54 else var =
new T(*(o.var));
56 else if (var) {
delete var; var =
nullptr; }
59 inline Option&
operator=(
Option &&o) noexcept {
if (&o ==
this)
return *
this;
delete var; var = o.var; o.var =
nullptr;
return *
this; }
63 inline operator bool() const noexcept {
return var !=
nullptr; }
65 inline T&
Get() noexcept {
return *var; }
67 inline const T&
Get() const noexcept {
return *var; }
71 inline const T&
operator*() const noexcept {
return *var; }
75 inline const T*
operator->() const noexcept {
return var; }
T & operator*() noexcept
Value access (undefined behaviour if the value is not set)
Option & operator=(Option &&o) noexcept
constexpr Option() noexcept
Default constructor.
const T * operator->() const noexcept
Method access (undefined behaviour if the value is not set)
Option(const T &value)
Constructor from value.
T & Get() noexcept
Value access (undefined behaviour if the value is not set)
Option & operator=(const Option &o)
Copy operator.
Option(Option &&o) noexcept
Option(const Option &o)
Copy constructor.
const T & Get() const noexcept
Value access (undefined behaviour if the value is not set)
T * operator->() noexcept
Method access (undefined behaviour if the value is not set)
A class to store an optional value.
const T & operator*() const noexcept
Value access (undefined behaviour if the value is not set)