diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-11-02 18:25:11 +0100 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-12-20 15:35:58 +0100 |
commit | afd8e711ab35e8d21bc9c8397f31dcf7ecdec2e3 (patch) | |
tree | d7a22e7fafb12dde1957fd2fe1c550359ce69b21 /asl/option.hpp | |
parent | 343d872be9f91e5fcb9167021790831458cbf19c (diff) |
Add value_or on option
Diffstat (limited to 'asl/option.hpp')
-rw-r--r-- | asl/option.hpp | 14 |
1 files changed, 14 insertions, 0 deletions
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<typename U>
+ constexpr T value_or(U&& other_value) const&
+ requires copy_constructible<T> && convertible<U&&, T>
+ {
+ return has_value() ? value() : static_cast<T>(ASL_FWD(other_value));
+ }
+
+ template<typename U>
+ constexpr T value_or(U&& other_value) &&
+ requires move_constructible<T> && convertible<U&&, T>
+ {
+ return has_value() ? ASL_MOVE(value()) : static_cast<T>(ASL_FWD(other_value));
+ }
};
template<typename T>
|