From f4bae8971cf2deee48f2544694aaa00ad17830c4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 1 Aug 2019 14:35:28 +0200 Subject: [PATCH] Documentation: Add a paragraph about NonnullOwnPtr to SmartPointers.md --- Documentation/SmartPointers.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Documentation/SmartPointers.md b/Documentation/SmartPointers.md index 76e2844563b..29104ecddfd 100644 --- a/Documentation/SmartPointers.md +++ b/Documentation/SmartPointers.md @@ -9,16 +9,18 @@ The reason for using these pointers is to make it explicit through code who owns ---- -## OwnPtr +## OwnPtr and NonnullOwnPtr OwnPtr is used for single-owner objects. An object held by an OwnPtr is owned by that OwnPtr, and not by anybody else. This means that the OwnPtr is responsible for deleting the pointee when the OwnPtr goes out of scope. -There is a make() helper that creates a new object and returns it wrapped in an OwnPtr. +NonnullOwnPtr is a special variant of OwnPtr with one additional property: it cannot be null. NonnullOwnPtr is suitable as a return type from functions that are guaranteed to never return null, and as an argument type where ownership is transferred, and the argument may not be null. In other words, if OwnPtr is "\*", then NonnullOwnPtr is "&". + +There is a make() helper that creates a new object and returns it wrapped in an NonnullOwnPtr. { - OwnPtr my_object = make(); + NonnullOwnPtr my_object = make(); my_object->do_stuff(); // my_object goes out of scope here, and the Foo will be deleted. }