Replace unstable coral::optional functions with operators
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
c36bf5b76c
commit
685e09412b
|
@ -283,7 +283,7 @@ export namespace coral {
|
||||||
|
|
||||||
optional(optional const & that) : buffer{0} {
|
optional(optional const & that) : buffer{0} {
|
||||||
if (that.has_value()) {
|
if (that.has_value()) {
|
||||||
(*reinterpret_cast<element *>(this->buffer)) = that.value();
|
(*reinterpret_cast<element *>(this->buffer)) = *that;
|
||||||
this->buffer[sizeof(element)] = 1;
|
this->buffer[sizeof(element)] = 1;
|
||||||
} else {
|
} else {
|
||||||
this->buffer[sizeof(element)] = 0;
|
this->buffer[sizeof(element)] = 0;
|
||||||
|
@ -303,7 +303,7 @@ export namespace coral {
|
||||||
* If the optional is empty, an empty optional will always be returned.
|
* If the optional is empty, an empty optional will always be returned.
|
||||||
*/
|
*/
|
||||||
template<typename functor> std::invoke_result_t<functor, element> map(functor const & apply) const {
|
template<typename functor> std::invoke_result_t<functor, element> map(functor const & apply) const {
|
||||||
if (this->has_value()) return apply(this->value());
|
if (this->has_value()) return apply(**this);
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -315,25 +315,15 @@ export namespace coral {
|
||||||
return this->has_value() ? *reinterpret_cast<element const *>(this->buffer) : fallback;
|
return this->has_value() ? *reinterpret_cast<element const *>(this->buffer) : fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
element & operator *() {
|
||||||
* Returns a reference to the contained value.
|
|
||||||
*
|
|
||||||
* *Note*: attempting to access the value of an empty optional will trigger safety-checked
|
|
||||||
* behavior.
|
|
||||||
*/
|
|
||||||
element & value() {
|
|
||||||
if (!this->has_value()) unreachable();
|
if (!this->has_value()) unreachable();
|
||||||
|
|
||||||
return *reinterpret_cast<element *>(this->buffer);
|
return *reinterpret_cast<element *>(this->buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
element const & operator *() const {
|
||||||
* Returns the contained value.
|
if (!this->has_value()) unreachable();
|
||||||
*
|
|
||||||
* *Note*: attempting to access the value of an empty optional will trigger safety-checked
|
|
||||||
* behavior.
|
|
||||||
*/
|
|
||||||
element const & value() const {
|
|
||||||
return *reinterpret_cast<element const *>(this->buffer);
|
return *reinterpret_cast<element const *>(this->buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue