summaryrefslogtreecommitdiff
path: root/Documentation/SmartPointers.md
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2022-02-03 17:19:53 +0200
committerAndreas Kling <kling@serenityos.org>2022-02-03 23:33:20 +0100
commit18b98f8c2893d2bd5d57ad5a4b8735c85b1d5d46 (patch)
tree9e039456e0eb654cbcead59747999e54a50a858c /Documentation/SmartPointers.md
parentba0a2a3e2f42f3f550aa6491c6031538b644c072 (diff)
downloadserenity-18b98f8c2893d2bd5d57ad5a4b8735c85b1d5d46.zip
AK: Convert the try_make<T> factory function to use ErrorOr
This allows more ergonomic memory allocation failure related error checking using the TRY macro.
Diffstat (limited to 'Documentation/SmartPointers.md')
-rw-r--r--Documentation/SmartPointers.md7
1 files changed, 4 insertions, 3 deletions
diff --git a/Documentation/SmartPointers.md b/Documentation/SmartPointers.md
index 9d63c2f335..b9d617b6a0 100644
--- a/Documentation/SmartPointers.md
+++ b/Documentation/SmartPointers.md
@@ -33,13 +33,14 @@ There is a `make<T>()` helper that constructs a new object and returns it wrappe
}
```
-The `try_make<T>()` helper attempts to construct a new object wrapped in an `OwnPtr`. All arguments passed to it are forwarded to `T`'s constructor. In case of allocation failure, a null pointer is returned. This allows the calling code to handle allocation failure as it wishes.
+The `try_make<T>()` helper attempts to construct a new object wrapped in an `ErrorOr<NonnullOwnPtr<T>>`. All arguments passed to it are forwarded to `T`'s constructor. In case of allocation failure, an ENOMEM error is returned. This allows the calling code to handle allocation failure as it wishes.
```cpp
-OwnPtr<Foo> my_object = try_make<Foo>();
-if (!my_object) {
+auto my_object_or_error = try_make<Foo>();
+if (my_object_or_error.is_error()) {
// handle allocation failure...
}
+auto my_object = my_object_or_error.release_value();
my_object->do_stuff();
```