9 #ifndef CPROVER_UTIL_SMALL_SHARED_N_WAY_PTR_H
10 #define CPROVER_UTIL_SMALL_SHARED_N_WAY_PTR_H
14 #include <type_traits>
20 template <std::size_t I,
typename... Ts>
24 typedef typename std::tuple_element<I, std::tuple<Ts...>>
::type type;
27 template <std::
size_t N,
typename Num>
36 template <std::size_t I,
typename pointee_baset,
typename... Ts>
41 if(p->template is_derived<I>())
43 typedef typename get_typet<I, Ts...>::type pointeet;
45 std::is_base_of<pointee_baset, pointeet>::value,
46 "indexed pointee type must be a subclass of the pointee base");
48 delete static_cast<pointeet *
>(p);
57 template <
typename pointee_baset,
typename... Ts>
64 typedef typename get_typet<0, Ts...>::type pointeet;
66 std::is_base_of<pointee_baset, pointeet>::value,
67 "indexed pointee type must be a subclass of the pointee base");
69 delete static_cast<pointeet *
>(p);
89 template <
typename... Ts>
94 std::tuple_size<std::tuple<Ts...>>::value;
98 "parameter pack should contain at least two types");
114 template <std::
size_t I>
121 p->template set_derived<I>();
192 template <std::
size_t I>
195 return p ==
nullptr ||
p->template is_derived<I>();
211 template <std::
size_t I>
216 return static_cast<typename
get_typet<I, Ts...
>::type *>(
p);
224 if(
p ==
nullptr || other.
p ==
nullptr)
230 explicit operator bool()
const
236 template <
typename T>
271 template <std::size_t I,
typename U,
typename V,
typename... Ts>
290 template <std::size_t I,
typename U,
typename V,
typename W,
typename... Ts>
294 template create_small_shared_n_way_ptr<I>(
298 template <
typename... Ts>
303 return lhs.
get() == rhs.
get();
306 template <
typename... Ts>
311 return lhs.
get() != rhs.
get();
314 template <std::
size_t N,
typename Num>
318 static_assert(std::is_unsigned<Num>::value,
"Num must be an unsigned type");
353 template <std::
size_t I>
356 static_assert(I < N,
"type index shall be within bounds");
362 template <std::
size_t I>
365 static_assert(I < N,
"type index shall be within bounds");
378 static const int bit_width = std::numeric_limits<Num>::digits;
380 static constexpr std::size_t
num_bits(
const std::size_t n)
382 return n < 2 ? 1 : 1 +
num_bits(n >> 1);
static const std::size_t type_bit_width
static const std::size_t use_count_bit_width
void increment_use_count()
static const Num use_count_mask
Num get_use_count() const
small_shared_n_way_pointee_baset & operator=(const small_shared_n_way_pointee_baset &)
small_shared_n_way_pointee_baset(const small_shared_n_way_pointee_baset &)
static const int bit_width
void decrement_use_count()
small_shared_n_way_pointee_baset()=default
static constexpr std::size_t num_bits(const std::size_t n)
bool is_same_type(const small_shared_n_way_pointee_baset &other) const
This class is similar to small_shared_ptrt and boost's intrusive_ptr.
void reset()
Clears this shared pointer.
~small_shared_n_way_ptrt()
static const std::size_t num_types
small_shared_n_way_ptrt & operator=(const small_shared_n_way_ptrt &rhs)
get_typet< I, Ts... >::type * get_derived() const
Get pointer to the managed object.
small_shared_n_way_ptrt & operator=(small_shared_n_way_ptrt &&rhs)
use_countt use_count() const
Get the use count of the pointed-to object.
small_shared_n_way_ptrt(T *p)
bool is_same_type(const small_shared_n_way_ptrt &other) const
Checks if the raw pointers held by *this and other both can be converted to a pointer to the same typ...
static small_shared_n_way_ptrt< Ts... > create_small_shared_n_way_ptr(typename get_typet< I, Ts... >::type *p)
Static factory method to construct a small shared n-way pointer, pointing to the given object *p of t...
pointee_baset * get() const
Get base type pointer to the managed object.
small_shared_n_way_ptrt(small_shared_n_way_ptrt &&rhs)
small_shared_n_way_ptrt(const small_shared_n_way_ptrt &rhs)
bool is_derived() const
Check if converting the held raw pointer to type Ts[I] is valid.
decltype(std::declval< typename get_typet< 0, Ts... >::type >() .get_use_count()) typedef use_countt
void swap(small_shared_n_way_ptrt &rhs)
bool operator==(const small_shared_n_way_ptrt< Ts... > &lhs, const small_shared_n_way_ptrt< Ts... > &rhs)
small_shared_n_way_ptrt< U, V, W > make_shared_3(Ts &&... ts)
Constructs a small shared n-way pointer, with three possible pointee types (i.e., n = 3),...
bool operator!=(const small_shared_n_way_ptrt< Ts... > &lhs, const small_shared_n_way_ptrt< Ts... > &rhs)
small_shared_n_way_ptrt< U, V > make_shared_2(Ts &&... ts)
Constructs a small shared n-way pointer, with two possible pointee types (i.e., n = 2),...
#define PRECONDITION(CONDITION)
static void destruct(pointee_baset *p)
static void destruct(pointee_baset *p)
Get the type with the given index in the parameter pack.
std::tuple_element< I, std::tuple< Ts... > >::type type