cprover
small_shared_two_way_ptrt< U, V > Class Template Referencefinal

This class is similar to small_shared_ptrt and boost's intrusive_ptr. More...

#include <small_shared_two_way_ptr.h>

+ Inheritance diagram for small_shared_two_way_ptrt< U, V >:
+ Collaboration diagram for small_shared_two_way_ptrt< U, V >:

Public Types

typedef small_shared_two_way_pointeet< use_counttpointeet
 

Public Member Functions

 small_shared_two_way_ptrt ()=default
 
 small_shared_two_way_ptrt (U *u)
 
 small_shared_two_way_ptrt (V *v)
 
 small_shared_two_way_ptrt (const small_shared_two_way_ptrt &rhs)
 
 small_shared_two_way_ptrt (small_shared_two_way_ptrt &&rhs)
 
small_shared_two_way_ptrtoperator= (const small_shared_two_way_ptrt &rhs)
 
small_shared_two_way_ptrtoperator= (small_shared_two_way_ptrt &&rhs)
 
 ~small_shared_two_way_ptrt ()
 
void swap (small_shared_two_way_ptrt &rhs)
 
use_countt use_count () const
 
bool is_derived_u () const
 Checks if converting the held raw pointer to U* is valid. More...
 
bool is_derived_v () const
 Checks if converting the held raw pointer to V* is valid. More...
 
pointeetget () const
 
U * get_derived_u () const
 
V * get_derived_v () const
 
bool is_same_type (const small_shared_two_way_ptrt &other) const
 Checks if the raw pointers held by *this and other both can be converted to either U* or V*. More...
 
 operator bool () const
 

Public Attributes

decltype(std::declval< U >().use_count()) typedef use_countt
 

Private Attributes

pointeetp = nullptr
 

Detailed Description

template<typename U, typename V>
class small_shared_two_way_ptrt< U, V >

This class is similar to small_shared_ptrt and boost's intrusive_ptr.

Like those, it stores the use count with the pointed-to object instead of in a separate control block. Additionally, it uses the MSB of the use count to indicate the type of the managed object (which is either of type U or V).

A possible use case is the implementation of data structures with sharing that consist of two different types of objects (such as a tree with internal nodes and leaf nodes). Storing the type with the use count avoids having to keep a separate type member or using typeid or dynamic_cast. Moreover, since the shared pointer is aware of the concrete type of the object being stored, it can delete it without requiring a virtual destructor or custom delete function (like std::shared_ptr).

Definition at line 34 of file small_shared_two_way_ptr.h.

Member Typedef Documentation

◆ pointeet

template<typename U , typename V >
typedef small_shared_two_way_pointeet<use_countt> small_shared_two_way_ptrt< U, V >::pointeet

Definition at line 39 of file small_shared_two_way_ptr.h.

Constructor & Destructor Documentation

◆ small_shared_two_way_ptrt() [1/5]

template<typename U , typename V >
small_shared_two_way_ptrt< U, V >::small_shared_two_way_ptrt ( )
default

◆ small_shared_two_way_ptrt() [2/5]

template<typename U , typename V >
small_shared_two_way_ptrt< U, V >::small_shared_two_way_ptrt ( U *  u)
inlineexplicit

Definition at line 46 of file small_shared_two_way_ptr.h.

◆ small_shared_two_way_ptrt() [3/5]

template<typename U , typename V >
small_shared_two_way_ptrt< U, V >::small_shared_two_way_ptrt ( V *  v)
inlineexplicit

Definition at line 55 of file small_shared_two_way_ptr.h.

◆ small_shared_two_way_ptrt() [4/5]

template<typename U , typename V >
small_shared_two_way_ptrt< U, V >::small_shared_two_way_ptrt ( const small_shared_two_way_ptrt< U, V > &  rhs)
inline

Definition at line 64 of file small_shared_two_way_ptr.h.

◆ small_shared_two_way_ptrt() [5/5]

template<typename U , typename V >
small_shared_two_way_ptrt< U, V >::small_shared_two_way_ptrt ( small_shared_two_way_ptrt< U, V > &&  rhs)
inline

Definition at line 74 of file small_shared_two_way_ptr.h.

◆ ~small_shared_two_way_ptrt()

template<typename U , typename V >
small_shared_two_way_ptrt< U, V >::~small_shared_two_way_ptrt ( )
inline

Definition at line 98 of file small_shared_two_way_ptr.h.

Member Function Documentation

◆ get()

template<typename U , typename V >
pointeet* small_shared_two_way_ptrt< U, V >::get ( ) const
inline

Definition at line 150 of file small_shared_two_way_ptr.h.

◆ get_derived_u()

template<typename U , typename V >
U* small_shared_two_way_ptrt< U, V >::get_derived_u ( ) const
inline

Definition at line 155 of file small_shared_two_way_ptr.h.

◆ get_derived_v()

template<typename U , typename V >
V* small_shared_two_way_ptrt< U, V >::get_derived_v ( ) const
inline

Definition at line 162 of file small_shared_two_way_ptr.h.

◆ is_derived_u()

template<typename U , typename V >
bool small_shared_two_way_ptrt< U, V >::is_derived_u ( ) const
inline

Checks if converting the held raw pointer to U* is valid.

Definition at line 139 of file small_shared_two_way_ptr.h.

◆ is_derived_v()

template<typename U , typename V >
bool small_shared_two_way_ptrt< U, V >::is_derived_v ( ) const
inline

Checks if converting the held raw pointer to V* is valid.

Definition at line 145 of file small_shared_two_way_ptr.h.

◆ is_same_type()

template<typename U , typename V >
bool small_shared_two_way_ptrt< U, V >::is_same_type ( const small_shared_two_way_ptrt< U, V > &  other) const
inline

Checks if the raw pointers held by *this and other both can be converted to either U* or V*.

Definition at line 171 of file small_shared_two_way_ptr.h.

◆ operator bool()

template<typename U , typename V >
small_shared_two_way_ptrt< U, V >::operator bool ( ) const
inlineexplicit

Definition at line 179 of file small_shared_two_way_ptr.h.

◆ operator=() [1/2]

template<typename U , typename V >
small_shared_two_way_ptrt& small_shared_two_way_ptrt< U, V >::operator= ( const small_shared_two_way_ptrt< U, V > &  rhs)
inline

Definition at line 81 of file small_shared_two_way_ptr.h.

◆ operator=() [2/2]

template<typename U , typename V >
small_shared_two_way_ptrt& small_shared_two_way_ptrt< U, V >::operator= ( small_shared_two_way_ptrt< U, V > &&  rhs)
inline

Definition at line 90 of file small_shared_two_way_ptr.h.

◆ swap()

template<typename U , typename V >
void small_shared_two_way_ptrt< U, V >::swap ( small_shared_two_way_ptrt< U, V > &  rhs)
inline

Definition at line 126 of file small_shared_two_way_ptr.h.

◆ use_count()

template<typename U , typename V >
use_countt small_shared_two_way_ptrt< U, V >::use_count ( ) const
inline

Definition at line 133 of file small_shared_two_way_ptr.h.

Member Data Documentation

◆ p

template<typename U , typename V >
pointeet* small_shared_two_way_ptrt< U, V >::p = nullptr
private

Definition at line 185 of file small_shared_two_way_ptr.h.

◆ use_countt

template<typename U , typename V >
decltype(std::declval<U>().use_count()) typedef small_shared_two_way_ptrt< U, V >::use_countt

Definition at line 37 of file small_shared_two_way_ptr.h.


The documentation for this class was generated from the following file: