From afd8e711ab35e8d21bc9c8397f31dcf7ecdec2e3 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Sat, 2 Nov 2024 18:25:11 +0100 Subject: Add value_or on option --- asl/option.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'asl/option.hpp') diff --git a/asl/option.hpp b/asl/option.hpp index 2651a00..bb266ab 100644 --- a/asl/option.hpp +++ b/asl/option.hpp @@ -373,6 +373,20 @@ public: return m_payload.as_init_unsafe(); } } + + template + constexpr T value_or(U&& other_value) const& + requires copy_constructible && convertible + { + return has_value() ? value() : static_cast(ASL_FWD(other_value)); + } + + template + constexpr T value_or(U&& other_value) && + requires move_constructible && convertible + { + return has_value() ? ASL_MOVE(value()) : static_cast(ASL_FWD(other_value)); + } }; template -- cgit