19template <
typename T>
class Arc {
27 static Arc<T> from_raw(
void *ptr)
noexcept {
34 static void *into_raw(
Arc<T> &&self)
noexcept {
37 return static_cast<void *
>(ptr);
42 static void *as_raw(
Arc<T> const &arc)
noexcept {
return arc.ptr; }
49 static Arc<T> &borrow_from_raw(
void *&ptr)
noexcept {
50 return *
reinterpret_cast<Arc<T> *
>(&ptr);
55 Arc(
Arc<T> const &other) noexcept : ptr (other.ptr) {
56 ++(ptr->strong_count);
63 size_t count = --(ptr->strong_count);
73 Arc(
Arc<T> &&rhs) noexcept : ptr (rhs.ptr) { rhs.ptr =
nullptr; }
78 void swap(
Arc<T> &rhs)
noexcept {
90 temporary.swap(*
this);
102 temporary.swap(*
this);
109 T &operator*()
const noexcept {
110 assert(ptr !=
nullptr);
115 T *operator->()
const noexcept {
116 assert(ptr !=
nullptr);