diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-11-17 07:52:39 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-11-18 12:21:57 +0000 |
commit | 56ab529752c18af07f566e2d75d3553d567b75a2 (patch) | |
tree | 03da65b196ce43aa8301d21a3c3189e7b899f960 /AK | |
parent | 862320828ff7af0a66d10ea79ca3c643309298ca (diff) | |
download | serenity-56ab529752c18af07f566e2d75d3553d567b75a2.zip |
AK: Add a concept for requiring that a function is fallible
This ensures that the function may be wrapped with TRY() and MUST().
Diffstat (limited to 'AK')
-rw-r--r-- | AK/Concepts.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/AK/Concepts.h b/AK/Concepts.h index 7186d6c2ef..f54028929a 100644 --- a/AK/Concepts.h +++ b/AK/Concepts.h @@ -111,12 +111,20 @@ concept IterableContainer = requires { declval<T>().begin() } -> IteratorPairWith<decltype(declval<T>().end())>; }; +template<typename Func, typename... Args> +concept FallibleFunction = requires(Func&& func, Args&&... args) { + func(forward<Args>(args)...).is_error(); + func(forward<Args>(args)...).release_error(); + func(forward<Args>(args)...).release_value(); +}; + // clang-format on } using AK::Concepts::Arithmetic; using AK::Concepts::ArrayLike; using AK::Concepts::Enum; +using AK::Concepts::FallibleFunction; using AK::Concepts::FloatingPoint; using AK::Concepts::Fundamental; using AK::Concepts::Integral; |