CppCoreGuidelines
CppCoreGuidelines copied to clipboard
Taxonomy of ownership semantics
The Core Guidelines say much about pointers, resources and ownership semantics, so I think it would be nice to provide a taxonomy for pointers, references and other objects with similar (pointer-like) semantics. I mean something like the taxonomy of value categories in [basic.lval], but, if possible, without overlaps. For example:
- Reference to resource (in general sense) ??? - need a better term
- owning reference - determines lifetime of the object referred
- collection
- unique_ptr
owner<T*>- rvalue-reference (when used with std::move)
- shared_ptr - partially determines lifetime
- weak_ptr - does not determine lifetime, but provides an interface to check validity
- view - does not determine lifetime, will cause undefined behavior if object is accessed via a view after end of it's lifetime
- string_view, array_view, etc.
- iterator
- lvalue reference
- raw pointer
- owning reference - determines lifetime of the object referred
Have you looked at the model being developed here: https://github.com/isocpp/CppCoreGuidelines/blob/master/docs/Lifetimes%20I%20and%20II%20-%20v0.9.1.pdf
? (around p. 6, under the heading "Indirections, Owners and Pointers")
Oops, no. Thanks for pointing out.