From 831973c39a65affd477ebf7275938475dca0fd35 Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 11 Mar 2023 17:41:11 +0100 Subject: [PATCH] Option: Allow direct access to the underlying value via operator-> Crashes if the Option is empty. --- libluna/include/luna/Option.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libluna/include/luna/Option.h b/libluna/include/luna/Option.h index 70266c0f..40307203 100644 --- a/libluna/include/luna/Option.h +++ b/libluna/include/luna/Option.h @@ -109,6 +109,13 @@ template 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();