diff options
Diffstat (limited to 'asl/base/functional.hpp')
-rw-r--r-- | asl/base/functional.hpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/asl/base/functional.hpp b/asl/base/functional.hpp index 5649bf8..7372001 100644 --- a/asl/base/functional.hpp +++ b/asl/base/functional.hpp @@ -54,6 +54,19 @@ constexpr auto invoke(is_func auto C::* f, auto&& self, Args&&... args) return ((*std::forward<decltype(self)>(self)).*f)(std::forward<Args>(args)...); } +template<typename R, typename F, typename... Args> +constexpr R invoke_r(F&& f, Args&&... args) +{ + if constexpr (is_void<R>) + { + static_cast<void>(invoke(std::forward<F>(f), std::forward<Args>(args)...)); + } + else + { + return invoke(std::forward<F>(f), std::forward<Args>(args)...); + } +} + template<typename Void, typename F, typename... Args> struct _invoke_result_helper; @@ -72,4 +85,8 @@ concept invocable = requires (F&& f, Args&&... args) invoke(std::forward<F>(f), std::forward<Args>(args)...); }; +template<typename R, typename F, typename... Args> +concept invocable_r = invocable<F, Args...> + && (is_void<R> || convertible_to<invoke_result_t<F, Args...>, R>); + } // namespace asl |