diff --git a/CMakeLists.txt b/CMakeLists.txt index b73a683..8099805 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.21 FATAL_ERROR) cmake_policy(SET CMP0097 NEW) -project(GeodeResult VERSION 1.1.1 LANGUAGES C CXX) +project(GeodeResult VERSION 1.2.1 LANGUAGES C CXX) add_library(GeodeResult INTERFACE) diff --git a/include/Geode/Result.hpp b/include/Geode/Result.hpp index 832a55b..994426a 100644 --- a/include/Geode/Result.hpp +++ b/include/Geode/Result.hpp @@ -1212,6 +1212,36 @@ namespace geode { return !(*this == other); } + /// @brief Unwraps the Ok value from the Result + /// @throw UnwrapException if the Result is Err + /// @return the Ok value + /// @note Same behavior as Result::unwrap() + constexpr decltype(auto) operator*() && noexcept + requires(!std::same_as) + { + return std::move(*this).unwrap(); + } + + /// @brief Unwraps the Ok value from the Result + /// @throw UnwrapException if the Result is Err + /// @return the Ok value + /// @note Same behavior as Result::unwrap() + constexpr decltype(auto) operator*() & noexcept + requires(!std::same_as) + { + return this->unwrap(); + } + + /// @brief Unwraps the Ok value from the Result + /// @throw UnwrapException if the Result is Err + /// @return the Ok value + /// @note Same behavior as Result::unwrap() + constexpr decltype(auto) operator*() const& noexcept + requires(!std::same_as) + { + return this->unwrap(); + } + /// @brief Returns true if the Result is Ok and the Ok value satisfies the predicate /// @param predicate the predicate to check the Ok value against /// @return true if the Result is Ok and the Ok value satisfies the predicate diff --git a/test/Misc.cpp b/test/Misc.cpp index 2546509..5198f87 100644 --- a/test/Misc.cpp +++ b/test/Misc.cpp @@ -177,4 +177,10 @@ TEST_CASE("Misc") { } } } -} \ No newline at end of file + + SECTION("Operator*") { + auto res = divideConstRefErrRef(32, 2); + REQUIRE(res.isOk()); + REQUIRE(*res == 16); + } +}