9#ifndef CPROVER_UTIL_SMALL_SHARED_N_WAY_PTR_H
10#define CPROVER_UTIL_SMALL_SHARED_N_WAY_PTR_H
20template <std::size_t
I,
typename...
Ts>
27template <std::
size_t N,
typename Num>
36template <std::size_t
I,
typename pointee_baset,
typename...
Ts>
45 std::is_base_of<pointee_baset, pointeet>::value,
46 "indexed pointee type must be a subclass of the pointee base");
57template <
typename pointee_baset,
typename...
Ts>
66 std::is_base_of<pointee_baset, pointeet>::value,
67 "indexed pointee type must be a subclass of the pointee base");
89template <
typename...
Ts>
94 std::tuple_size<std::tuple<
Ts...>>::value;
98 "parameter pack should contain at least two types");
100 typedef decltype(std::declval<
typename get_typet<0,
Ts...>::type>()
114 template <std::
size_t I>
122 p->increment_use_count();
133 p->increment_use_count();
186 return p ?
p->get_use_count() : 0;
192 template <std::
size_t I>
211 template <std::
size_t I>
224 if(
p ==
nullptr || other.
p ==
nullptr)
227 return p->is_same_type(*other.
p);
236 template <
typename T>
248 if(
p->get_use_count() > 1)
250 p->decrement_use_count();
271template <std::size_t
I,
typename U,
typename V,
typename...
Ts>
290template <std::size_t
I,
typename U,
typename V,
typename W,
typename...
Ts>
298template <
typename...
Ts>
303 return lhs.get() == rhs.get();
306template <
typename...
Ts>
311 return lhs.get() != rhs.get();
314template <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)
380 static constexpr std::size_t
num_bits(
const std::size_t
n) {
…}
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
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(const small_shared_n_way_pointee_baset &)
static const int bit_width
void decrement_use_count()
small_shared_n_way_pointee_baset()=default
small_shared_n_way_pointee_baset & operator=(const small_shared_n_way_pointee_baset &)
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.
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...
small_shared_n_way_ptrt()=default
~small_shared_n_way_ptrt()
static const std::size_t num_types
get_typet< I, Ts... >::type * get_derived() const
Get pointer to the managed object.
small_shared_n_way_ptrt & operator=(const small_shared_n_way_ptrt &rhs)
decltype(std::declval< typename get_typet< 0, Ts... >::type >() .get_use_count()) use_countt
pointee_baset * get() const
Get base type pointer to the managed object.
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...
small_shared_n_way_ptrt(small_shared_n_way_ptrt &&rhs)
small_shared_n_way_ptrt & operator=(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.
small_shared_n_way_pointee_baset< num_types, use_countt > pointee_baset
void swap(small_shared_n_way_ptrt &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),...
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)
#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