summaryrefslogtreecommitdiff
path: root/Kernel/MiniStdLib.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-09-05 13:32:15 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-05 14:08:12 +0200
commitb4d8e166d854679941396f59e5b43ce4a21e697a (patch)
treec4a8db05538b48c92faa31f1db3e2858872b2b6c /Kernel/MiniStdLib.cpp
parentfd44336ef8d0f1dac936d57a8d06f31bb6a3a0ba (diff)
downloadserenity-b4d8e166d854679941396f59e5b43ce4a21e697a.zip
AK: Add a TRY(expression) macro to simplify the unwrap-or-return pattern
The way we use classes like Kernel::KResultOr<T> and AK::Result<T, E> makes checking for errors (and short-circuiting returns) quite verbose. This patch adds a new TRY(expression) macro that either evaluates to the released result of the expression if successful, or returns the error if not. Before: auto foo_or_error = get_foo(); if (foo_or_error.is_error()) return foo_or_error.release_error(); auto foo = foo_or_error.release_value(); After: auto foo = TRY(get_foo()); The macro uses a GNU C++ extension which is supported by GCC, Clang, Intel C++, and possibly others. It's not *ideal*, but since it makes our codebase considerably nicer, let's try(!) it out. :^) Co-authored-by: Ali Mohammad Pur <mpfard@serenityos.org>
Diffstat (limited to 'Kernel/MiniStdLib.cpp')
0 files changed, 0 insertions, 0 deletions