CppCoreGuidelines icon indicating copy to clipboard operation
CppCoreGuidelines copied to clipboard

Taxonomy of ownership semantics

Open miyuki opened this issue 11 years ago • 2 comments

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

miyuki avatar Sep 27 '15 23:09 miyuki

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")

neilmacintosh avatar Sep 28 '15 00:09 neilmacintosh

Oops, no. Thanks for pointing out.

miyuki avatar Sep 28 '15 01:09 miyuki