From e626ffe58d038a6ed45bba41f1edd0dc699b4200 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 21 Aug 2026 21:25:55 +0200 Subject: kstd: add nodiscard to result success and failure --- libs/kstd/kstd/result.hpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'libs') diff --git a/libs/kstd/kstd/result.hpp b/libs/kstd/kstd/result.hpp index 7b027a8d..ae15f079 100644 --- a/libs/kstd/kstd/result.hpp +++ b/libs/kstd/kstd/result.hpp @@ -10,22 +10,33 @@ namespace kstd { + //! A type alias to hold results of functions that may fail. + //! + //! This is a convenience alias mapping to std::expected. It is intended to reduce the duplication of the unexpected + //! type across the codebase. template using result = std::expected; + //! Create a new success case. + //! + //! @param value The value to to stash in the success result. template requires(!std::is_void_v) - constexpr auto inline success(SuccessType && value) -> result> + [[nodiscard]] constexpr auto inline success(SuccessType && value) -> result> { return result>{std::in_place, std::forward(value)}; } - constexpr auto inline success() -> result + //! Create an empty success case. + [[nodiscard]] constexpr auto inline success() -> result { return result{std::in_place}; } - constexpr auto inline failure(error_code error) -> std::unexpected + //! Create a failure case. + //! + //! @param error The error that occurred. + [[nodiscard]] constexpr auto inline failure(error_code error) -> std::unexpected { return std::unexpected(error); } -- cgit v1.2.3