========================= Intrusive Smart Pointer ========================= :: #include namespace dplx::cncr {} .. namespace:: dplx::cncr Concepts -------- .. concept:: template \ ref_counted A type whose lifetime is managed by an internal reference counter and which has a :class:`reference_counted_traits reference_counted_traits>` specialization for controlling the reference counter. All functions are required to be ``noexcept``. **Notation** .. var:: RC &obj An lvalue reference to a reference counted object. **Valid Expressions** - :expr:`reference_counted_traits::counter_type` is the underlying integer type or void if unknown. - :expr:`reference_counted_traits::add_reference(obj)` increments :expr:`obj`'s reference count by one. - :expr:`reference_counted_traits::release(obj)` decrements :expr:`obj`'s reference count by one and atomically destructs it if the reference count reached zero. .. concept:: template inspectable_ref_counted Requires that a :concept:`ref_counted ref_counted>` type also provides a way to get an estimate of the current reference count. Not requiring the value to be excact allows reference counted objects shared across multiple threads to satisfy this. The only value required to be stable is ``1`` in which case our thread should be the only pointee. (With the exception of insane software architectures which retain non owning across threads). All functions are required to be ``noexcept``. **Notation** .. var:: RC &obj An lvalue reference to a reference counted object. **Valid Expressions** - :expr:`reference_counted_traits::counter_type` is the underlying integer type. - :expr:`reference_counted_traits::reference_count(obj)` returns an (estimate) of the current counter value of type ``counter_type``. .. concept:: template detail::dplx_ref_counted *Exposition Only* Describes the typical deeplex reference counting API. All functions are required to be ``noexcept``. **Notation** .. var:: RC const &obj An lvalue reference to a reference counted object. **Valid Expressions** - :expr:`obj.add_reference()` increments the reference counter. - :expr:`obj.release()` decrements the reference counter. - :expr:`obj.reference_count()` retrieves the current (approximate) reference count. Customization Points -------------------- .. class:: template \ reference_counted_traits This is a customization point i.e. there is no primary template definition. The implementation requirements are described by the :concept:`ref_counted` and :concept:`inspectable_ref_counted` concepts. .. class:: template \ reference_counted_traits The specialization of :class:`reference_counted_traits ` for types satisfying :concept:`detail::dplx_ref_counted`. The specialization satisfies :concept:`inspectable_ref_counted`. Factory Functions ----------------- .. function:: template \ constexpr auto intrusive_ptr_import(RC *obj) -> intrusive_ptr Creates a :expr:`intrusive_ptr` tracking :expr:`obj` assuming ownership of an existing reference (i.e. it doesn't call ``add_reference()``) It is a type deducing wrapper around :expr:`intrusive_ptr::import`. .. function:: template \ constexpr auto intrusive_ptr_acquire(RC *obj) -> intrusive_ptr Creates a :expr:`intrusive_ptr` tracking :expr:`obj` assuming ownership by acquiring a new reference (i.e. it calls ``add_reference()``). It is a type deducing wrapper around :expr:`intrusive_ptr::acquire`. Types ----- .. class:: template \ intrusive_ptr The usual intrusive smart pointer which poses as a pointer to the object whose lifetime it manages. The type satisfies `std::regular `_, i.e. it is default initializable, copyable and equality comparable. It is also swappable, totally ordered and contextually convertible to bool. Additionally the following members exist: .. type:: element_type = RC Exposes the type parameter for meta programming purposes. .. type:: handle_type = intrusive_ptr Exposes the type which is used for reference counting. It is exposed for compatibility with the aliasing variant :class:`intrusive_ptr\