From 79553ab1fa3d707612e80dd03bf95ca65fa0c411 Mon Sep 17 00:00:00 2001 From: Hannes Schulze Date: Tue, 4 Feb 2025 23:11:08 +0100 Subject: refactor file browser --- lib/nes/common/box.hh | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'lib/nes/common/box.hh') diff --git a/lib/nes/common/box.hh b/lib/nes/common/box.hh index 3a65613..7bf2848 100644 --- a/lib/nes/common/box.hh +++ b/lib/nes/common/box.hh @@ -1,6 +1,7 @@ #pragma once #include "nes/common/types.hh" +#include "nes/common/debug.hh" namespace nes { @@ -28,10 +29,30 @@ namespace nes auto operator=(box const&) -> box& = delete; auto operator=(box&&) -> box& = delete; - auto operator*() -> T& { return *get(); } - auto operator*() const -> T const& { return *get(); } - auto operator->() -> T* { return get(); } - auto operator->() const -> T const* { return get(); } + auto operator*() -> T& + { + NES_ASSERT(has_value() && "expected box to be non-empty"); + return *get(); + } + + auto operator*() const -> T const& + { + NES_ASSERT(has_value() && "expected box to be non-empty"); + return *get(); + } + + auto operator->() -> T* + { + NES_ASSERT(has_value() && "expected box to be non-empty"); + return get(); + } + + auto operator->() const -> T const* + { + NES_ASSERT(has_value() && "expected box to be non-empty"); + return get(); + } + operator bool() const { return has_value(); } auto has_value() const -> bool { return initialized_; } -- cgit v1.3.1