Add util::ResultPtr class
This is based on #25665. The non-base commits are:
-
120dfb39d46cAdd util::ResultPtr class -
6efb6d865e90Use ResultPtr<unique_ptr> instead of Result<unique_ptr>
The util::ResultPtr class is a wrapper for util::Result providing syntax sugar to make it less awkward to use with returned pointers. Instead of needing to be deferenced twice with **result or (*result)->member, it only needs to be dereferenced once with *result or result->member. Also when it is used in a boolean context, instead of evaluating to true when there is no error and the pointer is null, it evaluates to false so it is straightforward to determine whether the result points to something.
This PR is only partial a solution to #26004 because while it makes it easier to check for null pointer values, it does not make it impossible to return a null pointer value inside a successful result. It would be possible to enforce that successful results always contain non-null pointers by using a not_null type (https://github.com/bitcoin/bitcoin/issues/24423) in combination with ResultPtr, though.
In draft state because it's a partial solution to #26004 and could be discussed more
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Code Coverage
For detailed information about the code coverage, see the test coverage report.
Reviews
See the guideline for information on the review process. A summary of reviews will appear here.
Conflicts
Reviewers, this pull request conflicts with the following ones:
- #30364 (logging: Replace LogError and LogWarning with LogAlert by ryanofsky)
- #30344 (kernel: remove mempool_persist by theuni)
- #30342 (kernel, logging: Pass Logger instances to kernel objects by ryanofsky)
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
Rebased 4b8ee99dea4d990ac21dd6074a15511bc7842a8e -> 123788cf6dd74510e2a5b4ea3c566dc512a871ef (pr/bresult-ptr.1 -> pr/bresult-ptr.2, compare) due to conflict with #26005
Rebased a1dddc5a2a86908d9ea677875ad67a79d2c71d14 -> 8ecac0885ef5b6fc2313cd2f8dfb48c10a05db27 (pr/bresult-ptr.3 -> pr/bresult-ptr.4, compare) on top of https://github.com/bitcoin/bitcoin/pull/25665.
I also rewrote the commit and PR description. I think this is in a good state to review, despite being based on another PR.
Rebased 8ecac0885ef5b6fc2313cd2f8dfb48c10a05db27 -> 9f58eb795ec5592c59f9af3269f004e589a2368f (pr/bresult-ptr.4 -> pr/bresult-ptr.5, compare) on top of latest #25665 (no other changes)
🐙 This pull request conflicts with the target branch and needs rebase.