51struct _weak:
public std::weak_ptr<T> {
53 using super = std::weak_ptr<T>;
56 using super::weak_ptr;
58 _weak(
const _weak<T>& v)
noexcept: std::weak_ptr<T>(v) {}
59 _weak(_weak<T>&& v)
noexcept: std::weak_ptr<T>(std::move(v)) {}
60 _weak(
const std::weak_ptr<T>& v): std::weak_ptr<T>(v) {}
61 _weak(std::weak_ptr<T>&& v)
noexcept: std::weak_ptr<T>(std::move(v)) {}
63 _<T> lock()
const noexcept {
64 return static_cast<_<T>>(super::lock());
67 _weak& operator=(
const std::weak_ptr<T>& v)
noexcept {
68 super::weak_ptr::operator=(v);
72 _weak& operator=(std::weak_ptr<T>&& v)
noexcept {
73 super::weak_ptr::operator=(std::move(v));
77 _weak& operator=(
const _weak<T>& v)
noexcept {
78 super::weak_ptr::operator=(v);
82 _weak& operator=(_weak<T>&& v)
noexcept {
83 super::weak_ptr::operator=(std::move(v));
87 _weak& operator=(
const std::shared_ptr<T>& v)
noexcept {
88 super::weak_ptr::operator=(v);
92 _weak& operator=(std::shared_ptr<T>&& v)
noexcept {
93 super::weak_ptr::operator=(std::move(v));
97 _weak& operator=(
const _<T>& v)
noexcept {
98 super::weak_ptr::operator=(v);
102 _weak& operator=(
_<T>&& v)
noexcept {
103 super::weak_ptr::operator=(std::move(v));
177class _ :
public std::shared_ptr<T>
181 using super = std::shared_ptr<T>;
183 _(T* raw, std::nullopt_t): std::shared_ptr<T>(raw) {
187#ifdef AUI_SHARED_PTR_FIND_INSTANCES
188 friend API_AUI_CORE
void aui::impl::shared_ptr::printAllInstancesOf(
void* ptrToSharedPtr)
noexcept;
189 struct InstanceDescriber;
193 struct InstanceDescriber {
198 InstanceDescriber(_<T>* self): stacktrace(_<T>::makeStacktrace()), self(self), pointingTo(self->get()) {
199 if (pointingTo ==
nullptr)
return;
200 std::unique_lock lock(aui::impl::shared_ptr::instances().sync);
201 aui::impl::shared_ptr::instances().map[pointingTo].insert(self);
205 InstanceDescriber(
const InstanceDescriber&) =
delete;
206 InstanceDescriber(InstanceDescriber&&) =
delete;
208 ~InstanceDescriber() {
209 if (pointingTo ==
nullptr)
return;
210 auto& inst = aui::impl::shared_ptr::instances();
211 std::unique_lock lock(inst.sync);
212 if (
auto mapIt = inst.map.find(pointingTo); mapIt != inst.map.end()) {
213 auto setIt = mapIt->second.find(self);
215 mapIt->second.erase(setIt);
216 if (mapIt->second.empty()) {
222 } mInstanceDescriber =
this;
230#ifdef AUI_SHARED_PTR_FIND_INSTANCES
231 void printAllInstances() {
232 aui::impl::shared_ptr::printAllInstancesOf(
this);
234 void printAllInstances()
const {
235 const_cast<_<T>&
>(*this).printAllInstances();
239 using std::shared_ptr<T>::shared_ptr;
241 _(
const std::shared_ptr<T>& v): std::shared_ptr<T>(v) {}
242 _(std::shared_ptr<T>&& v)
noexcept: std::shared_ptr<T>(std::move(v)) {}
243 _(
const _& v): std::shared_ptr<T>(v) {}
244 _(_&& v)
noexcept: std::shared_ptr<T>(std::move(v)) {}
245 _(
const std::weak_ptr<T>& v): std::shared_ptr<T>(v) {}
246 _(
const _weak<T>& v): std::shared_ptr<T>(v) {}
248 _& operator=(
const _& rhs)
noexcept {
249 std::shared_ptr<T>::operator=(rhs);
253 _& operator=(_&& rhs)
noexcept {
254 std::shared_ptr<T>::operator=(std::forward<_>(rhs));
273 template<
typename SignalField,
typename Object,
typename Function>
274 inline _<T>& connect(SignalField signalField, Object
object, Function&& function);
276 template<
typename SignalField,
typename Function>
277 inline _<T>& connect(SignalField signalField, Function&& function);
280 template <
typename Functor>
281 inline _<T>& operator^(Functor&& functor) {
287 return super::operator->()->begin();
290 return super::operator->()->end();
293 return super::operator->()->begin();
296 return super::operator->()->end();
301 template<
typename Arg>
302 const _<T>& operator<<(Arg&& value)
const {
303 (*super::get()) << std::forward<Arg>(value);
307 template<
typename Arg>
308 _<T>& operator<<(Arg&& value) {
309 (*super::get()) << std::forward<Arg>(value);
313 template<
typename... Arg>
314 auto operator()(Arg&&... value)
const requires std::is_invocable_v<T, Arg...> {
315 return (*super::get())(std::forward<Arg>(value)...);
318 template<
typename Arg>
319 const _<T>& operator+(Arg&& value)
const {
320 (*super::get()) + std::forward<Arg>(value);
324 template<
typename Arg>
325 _<T>& operator+(Arg&& value) {
326 (*super::get()) + std::forward<Arg>(value);
330 template<
typename Arg>
331 const _<T>& operator*(Arg&& value) {
332 (*super::get()) * std::forward<Arg>(value);
337 std::add_lvalue_reference_t<T> operator*() const noexcept {
338 return super::operator*();
341 template<
typename Arg>
342 const _<T>& operator-(Arg&& value)
const {
343 (*super::get()) - std::forward<Arg>(value);
347 template<
typename Arg>
348 _<T>& operator-(Arg&& value) {
349 (*super::get()) - std::forward<Arg>(value);
352 template<
typename Arg>
354 (*super::get()) >> std::forward<Arg>(value);
358 template<
typename...Args>
359 _<T>& operator()(
const Args&... value) {
360 (*super::get())(value...);
363 template<
typename...Args>
364 auto operator()(Args&&... value) {
365 return (*super::get())(std::forward<Args>(value)...);