/*** Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: ExtendStlLikeSharedPtr.hpp Date: 2022-1-25 Author: Reece ***/ #pragma once namespace Aurora::Memory { template struct ExSharedPtr : public Base_t { bool cached {}; using element_type = Base_t::element_type; using weak_type = Base_t::weak_type; using base_type = Base_t; using Base_t::Base_t; ExSharedPtr(Base_t &&in) : Base_t(in) {} ExSharedPtr(const Base_t &in) : Base_t(in) {} operator Base_t() const noexcept { return *this; } ExSharedPtr &operator =(const Base_t &in) noexcept { Base_t::operator=(in); return *this; } template TType2_t &operator*() const { throwif(); return Base_t::operator*(); } template TType2_t *operator->() const { throwif(); return Base_t::operator->(); } template TType2_t &operator*() { throwif(); return Base_t::operator*(); } template TType2_t *operator->() { throwif(); return Base_t::operator->(); } private: auline void _cache() { cached = Base_t::operator bool(); } auline void throwif() const { if (!cached) [[unlikely]] { if (!Base_t::operator bool()) [[likely]] { AU_THROW_STRING("ExSharedPointer Null Access Violation"); } } } auline void throwif() { if (!cached) [[unlikely]] { cached = Base_t::operator bool(); if (!cached) [[likely]] { AU_THROW_STRING("ExSharedPointer Null Access Violation"); } } } }; template struct ExSharedFromThis : Base_t { ExSharedPtr> SharedFromThis() { return Base_t::shared_from_this(); } }; }