Go to the documentation of this file.
23 #ifndef STDEXT_SHARED_OBJECT_H
24 #define STDEXT_SHARED_OBJECT_H
27 #include <type_traits>
47 void dec_ref() {
if(--refs == 0)
delete this; }
56 std::atomic<refcount_t> refs;
63 class shared_object_ptr
70 static_assert(std::is_base_of<shared_object, T>::value,
"classes using shared_object_ptr must be a derived of stdext::shared_object");
71 if(px !=
nullptr && add_ref)
82 T*
get()
const {
return px; }
89 T&
operator*()
const { assert(px !=
nullptr);
return *px; }
90 T*
operator->()
const { assert(px !=
nullptr);
return px; }
106 void dec_ref() { ((shared_object*)px)->dec_ref(); }
126 template<
class E,
class T,
class Y> std::basic_ostream<E, T>&
operator<<(std::basic_ostream<E, T>& os,
shared_object_ptr<Y> const& p) { os << p.get();
return os; }
shared_object_ptr(shared_object_ptr &&rhs)
void swap(stdext::packed_vector< T, U > &lhs, stdext::packed_vector< T, U > &rhs)
shared_object_ptr & operator=(T *rhs)
bool operator==(shared_object_ptr< T > const &a, shared_object_ptr< U > const &b)
size_t operator()(const stdext::shared_object_ptr< T > &p) const
shared_object_ptr< T > const_pointer_cast(shared_object_ptr< U > const &p)
refcount_t use_count() const
shared_object_ptr & operator=(shared_object_ptr const &rhs)
bool operator!=(shared_object_ptr< T > const &a, shared_object_ptr< U > const &b)
stdext::shared_object_ptr< T > const_self_cast()
std::basic_ostream< E, T > & operator<<(std::basic_ostream< E, T > &os, shared_object_ptr< Y > const &p)
shared_object_ptr(T *p, bool add_ref=true)
T * get_pointer(shared_object_ptr< T > const &p)
bool operator<(shared_object_ptr< T > const &a, shared_object_ptr< T > const &b)
shared_object_ptr & operator=(shared_object_ptr< U > const &rhs)
stdext::shared_object_ptr< T > static_self_cast()
void swap(shared_object_ptr &rhs)
stdext::shared_object_ptr< T > make_shared_object(Args... args)
stdext::shared_object_ptr< T > dynamic_self_cast()
shared_object_ptr & operator=(shared_object_ptr &&rhs)
T *shared_object_ptr::* unspecified_bool_type
shared_object_ptr(shared_object_ptr< U > const &rhs, typename std::enable_if< std::is_convertible< U *, T * >::value, U * >::type=nullptr)
shared_object_ptr(shared_object_ptr const &rhs)
shared_object_ptr< T > dynamic_pointer_cast(shared_object_ptr< U > const &p)
shared_object_ptr< T > static_pointer_cast(shared_object_ptr< U > const &p)