18struct Default_ref_counter
 
   20  void h_drop_ref(T *p) 
noexcept 
   22    if (p->remove_ref() == 0)
 
   26  void h_take_ref(T *p) 
noexcept 
   38template<
typename T, 
template< 
typename X > 
class CNT = Default_ref_counter>
 
   68  template< 
typename X > 
class CNT = Default_ref_counter
 
   70class Ref_ptr : 
public Ref_ptr_base, 
private CNT<T>
 
   73  typedef decltype(
nullptr) Null_type;
 
   74  typedef Weak_ptr<T, CNT> Wp;
 
   80  Ref_ptr(Ref_ptr_base::Default_value v)
 
   81  : _p(reinterpret_cast<T*>(static_cast<unsigned long>(v))) {}
 
   88  Ref_ptr(Wp 
const &o) noexcept : _p(o.ptr())
 
 
   92  Ref_ptr(
decltype(
nullptr) n) noexcept : _p(n) {}
 
  114  Ref_ptr(T *o, [[maybe_unused]] 
bool d) noexcept : _p(o) { }
 
  148  template<
typename OT>
 
  161  template< 
typename OT >
 
  169  void operator = (
Ref_ptr<T> const &o) 
noexcept 
  179  void operator = (Null_type) 
noexcept 
  185  template<
typename OT>
 
  187  { _p = o.release(); }
 
  190  { _p = o.release(); }
 
  192  template< 
typename OT >
 
  208  [[nodiscard]] 
explicit operator bool () const noexcept { 
return _p; }
 
  210  T *operator -> () const noexcept
 
  213  [[nodiscard]] 
bool operator == (
Ref_ptr const &o) 
const noexcept 
  214  { 
return _p == o._p; }
 
  216  [[nodiscard]] 
bool operator != (
Ref_ptr const &o) 
const noexcept 
  217  { 
return _p != o._p; }
 
  219  [[nodiscard]] 
bool operator < (
Ref_ptr const &o) 
const noexcept 
  220  { 
return _p < o._p; }
 
  222  [[nodiscard]] 
bool operator <= (
Ref_ptr const &o) 
const noexcept 
  223  { 
return _p <= o._p; }
 
  225  [[nodiscard]] 
bool operator > (
Ref_ptr const &o) 
const noexcept 
  226  { 
return _p > o._p; }
 
  228  [[nodiscard]] 
bool operator >= (
Ref_ptr const &o) 
const noexcept 
  229  { 
return _p >= o._p; }
 
  231  [[nodiscard]] 
bool operator == (T 
const *o) 
const noexcept 
  234  [[nodiscard]] 
bool operator < (T 
const *o) 
const noexcept 
  237  [[nodiscard]] 
bool operator <= (T 
const *o) 
const noexcept 
  240  [[nodiscard]] 
bool operator > (T 
const *o) 
const noexcept 
  243  [[nodiscard]] 
bool operator >= (T 
const *o) 
const noexcept 
  247  void __drop_ref() noexcept
 
  250      static_cast<CNT<T>*
>(
this)->h_drop_ref(_p);
 
  253  void __take_ref() noexcept
 
  256      static_cast<CNT<T>*
>(
this)->h_take_ref(_p);
 
 
  263template<
typename T, 
template< 
typename X > 
class CNT>
 
  268  typedef Ref_ptr<T, CNT> Rp;
 
  271  Weak_ptr() = 
default;
 
  272  Weak_ptr(
decltype(
nullptr)) : _p(nullptr) {}
 
  274  explicit Weak_ptr(
int x) 
noexcept 
  277  { 
if (x != 0) __builtin_trap(); }
 
  279  Weak_ptr(Rp 
const &o) noexcept : _p(o.ptr()) {}
 
  280  explicit Weak_ptr(T *o) noexcept : _p(o) {}
 
  282  template<
typename OT>
 
  283  Weak_ptr(Weak_ptr<OT, CNT> 
const &o) noexcept : _p(o.ptr()) {}
 
  285  Weak_ptr(Weak_ptr<T, CNT> 
const &o) noexcept : _p(o._p) {}
 
  287  Weak_ptr<T, CNT> &operator = (
const Weak_ptr<T, CNT> &o) = 
default;
 
  289  T *get() const noexcept { 
return _p; }
 
  290  T *ptr() const noexcept { 
return _p; }
 
  292  T *operator -> () const noexcept { 
return _p; }
 
  293  operator Null_type 
const * () 
const noexcept 
  294  { 
return reinterpret_cast<Null_type const*
>(_p); }
 
  300template<
typename OT, 
typename T> 
inline 
  302{ 
return ref_ptr(
static_cast<OT*
>(o.ptr())); }
 
  304template< 
typename T >
 
  308template< 
typename T >
 
  309inline Weak_ptr<T> weak_ptr(T *t)
 
  310{ 
return Weak_ptr<T>(t); }
 
  316  mutable int _ref_cnt;
 
  319  Ref_obj() : _ref_cnt(0)  {}
 
  320  void add_ref() const noexcept { ++_ref_cnt; }
 
  321  int remove_ref() const noexcept { 
return --_ref_cnt; }
 
  324template< 
typename T, 
typename... Args >
 
  326make_ref_obj(Args &&... args)
 
  327{ 
return cxx::Ref_ptr<T>(
new T(cxx::forward<Args>(args)...)); }
 
  329template<
typename T, 
typename U>
 
  331dynamic_pointer_cast(
Ref_ptr<U> const &p) 
noexcept 
  334  return Ref_ptr<T>(
dynamic_cast<T *
>(p.get()));
 
  337template<
typename T, 
typename U>
 
  339static_pointer_cast(
Ref_ptr<U> const &p) 
noexcept 
A reference-counting pointer with automatic cleanup.
 
Ref_ptr(Wp const &o) noexcept
Create a shared pointer from a weak pointer.
 
Ref_ptr() noexcept
Default constructor creates a pointer with no managed object.
 
Ref_ptr(decltype(nullptr) n) noexcept
allow creation from nullptr
 
T * get() const noexcept
Return a raw pointer to the object this shared pointer points to.
 
T * release() noexcept
Release the shared pointer without removing the reference.
 
Ref_ptr(X *o) noexcept
Create a shared pointer from a raw pointer.
 
Ref_ptr(T *o, bool d) noexcept
Create a shared pointer from a raw pointer without creating a new reference.
 
T * ptr() const noexcept
Return a raw pointer to the object this shared pointer points to.
 
L4 compiler related defines.
 
#define L4_DEPRECATED(s)
Mark symbol deprecated.