10#include <lagrange/internal/smart_ptr/control_block.h>
11#include <lagrange/internal/shared_ptr.h>
34 using element_type =
typename std::remove_extent<T>::type;
50 , _control_block{sp._control_block}
52 if (_control_block) _control_block->inc_wref();
59 , _control_block{wp._control_block}
61 if (_control_block) _control_block->inc_wref();
69 , _control_block{wp._control_block}
71 if (_control_block) _control_block->inc_wref();
78 if (_control_block) _control_block->dec_wref();
83 weak_ptr& operator=(
const weak_ptr& wp)
noexcept
90 weak_ptr& operator=(
const weak_ptr<U>& wp)
noexcept
97 weak_ptr& operator=(
const shared_ptr<U>& sp)
noexcept
110 swap(_control_block, wp._control_block);
119 long use_count() const noexcept {
return (_control_block) ? _control_block->use_count() : 0; }
122 bool expired() const noexcept {
return (_control_block) ? _control_block->expired() :
false; }
Definition: control_block.h:24
NOT implemented: custom allocator support.
Definition: shared_ptr.h:110
Definition: weak_ptr.h:26
constexpr weak_ptr() noexcept
Default constructor, creates an empty weak_ptr Postconditions: use_count() == 0.
Definition: weak_ptr.h:40
void reset() noexcept
Resets *this to empty.
Definition: weak_ptr.h:114
long use_count() const noexcept
Gets use_count.
Definition: weak_ptr.h:119
weak_ptr(shared_ptr< U > const &sp) noexcept
Conversion constructor: shares ownership with sp Postconditions: use_count() == sp....
Definition: weak_ptr.h:48
weak_ptr(weak_ptr const &wp) noexcept
Copy constructor: shares ownership with wp Postconditions: use_count() == wp.use_count().
Definition: weak_ptr.h:57
weak_ptr(weak_ptr< U > const &wp) noexcept
Copy constructor: shares ownership with wp Postconditions: use_count() == wp.use_count().
Definition: weak_ptr.h:67
bool expired() const noexcept
Checks if use_count == 0.
Definition: weak_ptr.h:122
shared_ptr< T > lock() const noexcept
Checks if there is a managed object.
Definition: weak_ptr.h:125
void swap(weak_ptr &wp) noexcept
Exchanges the contents of *this and sp.
Definition: weak_ptr.h:106
constexpr void swap(function_ref< R(Args...)> &lhs, function_ref< R(Args...)> &rhs) noexcept
Swaps the referred callables of lhs and rhs.
Definition: function_ref.h:114
nullptr_t, size_t, ptrdiff_t basic_ostream bad_weak_ptr extent, remove_extent, is_array,...
Definition: attribute_string_utils.h:21
void swap(shared_ptr< T > &sp1, shared_ptr< T > &sp2)
Swaps with another shared_ptr.
Definition: shared_ptr.h:384