-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nixd/lib/Controller: use
CheckReturn
to simplify early-returns (NFC) (
#623)
- Loading branch information
Showing
13 changed files
with
287 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
/// \brief Used for simplify early-returns. | ||
/// | ||
/// const auto *foo = checkReturn(get(), nullptr) | ||
#define CheckReturn(x, Ret) \ | ||
({ \ | ||
decltype(x) temp = (x); \ | ||
if (!temp) [[unlikely]] { \ | ||
return Ret; \ | ||
} \ | ||
temp; \ | ||
}) | ||
|
||
/// \brief Variant of `CheckReturn`, but returns default constructed `CheckTy` | ||
#define CheckDefault(x) CheckReturn(x, CheckTy{}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.