40template <
typename T>
class Arc {
43 explicit Arc(T value) noexcept
48 static Arc<T> from_raw(
void *ptr)
noexcept {
56 static void *into_raw(Arc<T> &&self)
noexcept {
59 return static_cast<void *
>(ptr);
64 static void *as_raw(Arc<T>
const &arc)
noexcept {
return arc.ptr; }
71 static Arc<T> &borrow_from_raw(
void *&ptr)
noexcept {
72 return *
reinterpret_cast<Arc<T> *
>(&ptr);
77 Arc(Arc<T>
const &other) noexcept : ptr (other.ptr) {
78 ++(ptr->strong_count);
85 size_t count = --(ptr->strong_count);
95 Arc(Arc<T> &&rhs) noexcept : ptr (rhs.ptr) { rhs.ptr =
nullptr; }
100 void swap(Arc<T> &rhs)
noexcept {
109 Arc<T> &operator=(Arc<T>
const &rhs)
noexcept {
112 temporary.swap(*
this);
120 Arc<T> &operator=(Arc<T> &&rhs)
noexcept {
124 temporary.swap(*
this);
131 T &operator*()
const noexcept {
132 assert(ptr !=
nullptr);
137 T *operator->()
const noexcept {
138 assert(ptr !=
nullptr);