6#ifndef SL_UTILITY_NULLABLES_OR_ELSE_HPP
7#define SL_UTILITY_NULLABLES_OR_ELSE_HPP
14namespace sl::nullables::detail
16 template <nullable TNullable, std::invocable TFunc>
17 requires std::is_void_v<std::invoke_result_t<TFunc>>
18 || std::constructible_from<std::remove_cvref_t<TNullable>, std::invoke_result_t<TFunc>>
20 constexpr std::remove_cvref_t<TNullable>
or_else(TNullable&& nullableObj, TFunc&& func)
22 using result_t = std::remove_cvref_t<TNullable>;
24 if (nullableObj == null_v<TNullable>)
26 if constexpr (std::is_void_v<std::invoke_result_t<TFunc>>)
28 std::invoke(std::forward<TFunc>(func));
29 return result_t{ null_v<TNullable> };
33 return result_t{ std::invoke(std::forward<TFunc>(func)) };
36 return std::forward<TNullable>(nullableObj);
39 class or_else_caller_fn
42 template <nullable TNullable, std::invocable TFunc>
44 constexpr std::remove_cvref_t<TNullable> operator ()
46 TNullable&& nullableObj,
49 noexcept(
noexcept(
or_else(std::declval<TNullable>(), std::declval<TFunc>())))
52 std::forward<TNullable>(nullableObj),
53 std::forward<TFunc>(func)
90 inline constexpr auto or_else = []<
class Fn>(Fn&& fn)
noexcept(std::is_nothrow_constructible_v<std::remove_cvref_t<Fn>, Fn>)
The core algorithm helper, which executes the held operation when used as the right-hand-side of oper...
Definition: base.hpp:216
constexpr auto bind_back
Helper function, which generates a forwarding call wrapper for the given function and curries the par...
Definition: bind_back.hpp:100
constexpr auto or_else
Returns the nullable if it's not equal to its ''null''-object. Executes the passed function otherwise...
Definition: or_else.hpp:90
Definition: adapter.hpp:19