diff --git a/source/coral.cpp b/source/coral.cpp index 405a3e7..3a30715 100644 --- a/source/coral.cpp +++ b/source/coral.cpp @@ -283,7 +283,7 @@ export namespace coral { optional(optional const & that) : buffer{0} { if (that.has_value()) { - (*reinterpret_cast(this->buffer)) = that.value(); + (*reinterpret_cast(this->buffer)) = *that; this->buffer[sizeof(element)] = 1; } else { this->buffer[sizeof(element)] = 0; @@ -303,7 +303,7 @@ export namespace coral { * If the optional is empty, an empty optional will always be returned. */ template std::invoke_result_t map(functor const & apply) const { - if (this->has_value()) return apply(this->value()); + if (this->has_value()) return apply(**this); return {}; } @@ -315,25 +315,15 @@ export namespace coral { return this->has_value() ? *reinterpret_cast(this->buffer) : fallback; } - /** - * Returns a reference to the contained value. - * - * *Note*: attempting to access the value of an empty optional will trigger safety-checked - * behavior. - */ - element & value() { + element & operator *() { if (!this->has_value()) unreachable(); return *reinterpret_cast(this->buffer); } - /** - * Returns the contained value. - * - * *Note*: attempting to access the value of an empty optional will trigger safety-checked - * behavior. - */ - element const & value() const { + element const & operator *() const { + if (!this->has_value()) unreachable(); + return *reinterpret_cast(this->buffer); }