Option: Allow direct access to the underlying value via operator->

Crashes if the Option is empty.
This commit is contained in:
apio 2023-03-11 17:41:11 +01:00
parent 30deed2820
commit 831973c39a
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -109,6 +109,13 @@ template <typename T> class Option
return true;
}
// NOTE: This should also exist in Result.
T* operator->()
{
expect(has_value(), "Option::operator-> called on an empty Option");
return &m_storage.fetch_reference();
}
~Option()
{
if (has_value()) m_storage.destroy();