diff --git a/develop/singles/headers/meta.hpp/meta_all.hpp b/develop/singles/headers/meta.hpp/meta_all.hpp index 6d37663..4a1ec69 100644 --- a/develop/singles/headers/meta.hpp/meta_all.hpp +++ b/develop/singles/headers/meta.hpp/meta_all.hpp @@ -8,7 +8,6 @@ #include #include -#include #include #include #include @@ -889,202 +888,6 @@ namespace meta_hpp::detail } } -namespace meta_hpp::detail -{ - template < typename Derived > - class intrusive_ref_counter; - - template < typename Derived > - void intrusive_ptr_add_ref(const intrusive_ref_counter* ptr); - - template < typename Derived > - void intrusive_ptr_release(const intrusive_ref_counter* ptr); - - template < typename Derived > - class intrusive_ref_counter { - public: - intrusive_ref_counter() = default; - - intrusive_ref_counter(intrusive_ref_counter&&) noexcept {} - - intrusive_ref_counter(const intrusive_ref_counter&) noexcept {} - - intrusive_ref_counter& operator=(intrusive_ref_counter&&) noexcept { - return *this; - } - - intrusive_ref_counter& operator=(const intrusive_ref_counter&) noexcept { - return *this; - } - - [[nodiscard]] std::size_t get_use_count() const noexcept { - return counter_.load(std::memory_order_acquire); - } - - protected: - ~intrusive_ref_counter() = default; - - private: - mutable std::atomic_size_t counter_{}; - friend void intrusive_ptr_add_ref(const intrusive_ref_counter* ptr); - friend void intrusive_ptr_release(const intrusive_ref_counter* ptr); - }; - - template < typename Derived > - void intrusive_ptr_add_ref(const intrusive_ref_counter* ptr) { - ptr->counter_.fetch_add(1, std::memory_order_acq_rel); - } - - template < typename Derived > - void intrusive_ptr_release(const intrusive_ref_counter* ptr) { - if ( ptr->counter_.fetch_sub(1, std::memory_order_acq_rel) == 1 ) { - // NOLINTNEXTLINE(*-owning-memory) - delete static_cast(ptr); - } - } -} - -namespace meta_hpp::detail -{ - template < typename T > - class intrusive_ptr final { - public: - intrusive_ptr() = default; - - ~intrusive_ptr() { - if ( ptr_ != nullptr ) { - intrusive_ptr_release(ptr_); - } - } - - intrusive_ptr(T* ptr, bool add_ref = true) - : ptr_{ptr} { - if ( ptr_ != nullptr && add_ref ) { - intrusive_ptr_add_ref(ptr_); - } - } - - intrusive_ptr(intrusive_ptr&& other) noexcept - : ptr_{other.ptr_} { - other.ptr_ = nullptr; - } - - intrusive_ptr(const intrusive_ptr& other) - : ptr_{other.ptr_} { - if ( ptr_ != nullptr ) { - intrusive_ptr_add_ref(ptr_); - } - } - - intrusive_ptr& operator=(T* ptr) noexcept { - intrusive_ptr{ptr}.swap(*this); - return *this; - } - - intrusive_ptr& operator=(intrusive_ptr&& other) noexcept { - intrusive_ptr{std::move(other)}.swap(*this); - return *this; - } - - intrusive_ptr& operator=(const intrusive_ptr& other) { - intrusive_ptr{other}.swap(*this); - return *this; - } - - void reset() { - intrusive_ptr{}.swap(*this); - } - - void reset(T* ptr) { - intrusive_ptr{ptr}.swap(*this); - } - - void reset(T* ptr, bool add_ref) { - intrusive_ptr{ptr, add_ref}.swap(*this); - } - - T* release() noexcept { - return std::exchange(ptr_, nullptr); - } - - [[nodiscard]] T* get() const noexcept { - return ptr_; - } - - [[nodiscard]] T& operator*() const noexcept { - return *ptr_; - } - - [[nodiscard]] T* operator->() const noexcept { - return ptr_; - } - - [[nodiscard]] explicit operator bool() const noexcept { - return ptr_ != nullptr; - } - - void swap(intrusive_ptr& other) noexcept { - ptr_ = std::exchange(other.ptr_, ptr_); - } - - [[nodiscard]] std::size_t get_hash() const noexcept { - return hash_combiner{}(ptr_); - } - - [[nodiscard]] bool operator==(const intrusive_ptr& other) const noexcept { - return ptr_ == other.ptr_; - } - - [[nodiscard]] std::strong_ordering operator<=>(const intrusive_ptr& other) const noexcept { - return ptr_ <=> other.ptr_; - } - - private: - T* ptr_{}; - }; - - template < typename T, typename... Args > - intrusive_ptr make_intrusive(Args&&... args) { - // NOLINTNEXTLINE(*-owning-memory) - return new T(std::forward(args)...); - } - - template < typename T > - void swap(intrusive_ptr& l, intrusive_ptr& r) noexcept { - return l.swap(r); - } - - template < typename T > - [[nodiscard]] bool operator==(const intrusive_ptr& l, const T* r) noexcept { - return l.get() == r; - } - - template < typename T > - [[nodiscard]] std::strong_ordering operator<=>(const intrusive_ptr& l, const T* r) noexcept { - return l.get() <=> r; - } - - template < typename T > - [[nodiscard]] bool operator==(const intrusive_ptr& l, std::nullptr_t) noexcept { - return l.get() == nullptr; - } - - template < typename T > - [[nodiscard]] std::strong_ordering operator<=>(const intrusive_ptr& l, std::nullptr_t) noexcept { - return l.get() <=> nullptr; - } -} - -namespace std -{ - template < typename T > - struct hash> { - size_t operator()(const meta_hpp::detail::intrusive_ptr& ip) const noexcept { - return ip.get_hash(); - } - }; -} - namespace meta_hpp::detail { template < typename T > @@ -1509,15 +1312,15 @@ namespace meta_hpp struct scope_state; struct variable_state; - using argument_state_ptr = intrusive_ptr; - using constructor_state_ptr = intrusive_ptr; - using destructor_state_ptr = intrusive_ptr; - using evalue_state_ptr = intrusive_ptr; - using function_state_ptr = intrusive_ptr; - using member_state_ptr = intrusive_ptr; - using method_state_ptr = intrusive_ptr; - using scope_state_ptr = intrusive_ptr; - using variable_state_ptr = intrusive_ptr; + using argument_state_ptr = std::shared_ptr; + using constructor_state_ptr = std::shared_ptr; + using destructor_state_ptr = std::shared_ptr; + using evalue_state_ptr = std::shared_ptr; + using function_state_ptr = std::shared_ptr; + using member_state_ptr = std::shared_ptr; + using method_state_ptr = std::shared_ptr; + using scope_state_ptr = std::shared_ptr; + using variable_state_ptr = std::shared_ptr; } template < typename T > @@ -3878,7 +3681,7 @@ namespace meta_hpp namespace meta_hpp::detail { - struct argument_state final : intrusive_ref_counter { + struct argument_state final { argument_index index; metadata_map metadata; @@ -3889,7 +3692,7 @@ namespace meta_hpp::detail explicit argument_state(argument_index index, metadata_map metadata); }; - struct constructor_state final : intrusive_ref_counter { + struct constructor_state final { using create_impl = fixed_function)>; using create_at_impl = fixed_function)>; using create_error_impl = fixed_function)>; @@ -3907,7 +3710,7 @@ namespace meta_hpp::detail explicit constructor_state(constructor_index index, metadata_map metadata); }; - struct destructor_state final : intrusive_ref_counter { + struct destructor_state final { using destroy_impl = fixed_function; using destroy_at_impl = fixed_function; using destroy_error_impl = fixed_function; @@ -3924,7 +3727,7 @@ namespace meta_hpp::detail explicit destructor_state(destructor_index index, metadata_map metadata); }; - struct evalue_state final : intrusive_ref_counter { + struct evalue_state final { evalue_index index; metadata_map metadata; @@ -3936,7 +3739,7 @@ namespace meta_hpp::detail explicit evalue_state(evalue_index index, metadata_map metadata); }; - struct function_state final : intrusive_ref_counter { + struct function_state final { using invoke_impl = fixed_function)>; using invoke_error_impl = fixed_function)>; @@ -3952,7 +3755,7 @@ namespace meta_hpp::detail explicit function_state(function_index index, metadata_map metadata); }; - struct member_state final : intrusive_ref_counter { + struct member_state final { using getter_impl = fixed_function; using setter_impl = fixed_function; @@ -3972,7 +3775,7 @@ namespace meta_hpp::detail explicit member_state(member_index index, metadata_map metadata); }; - struct method_state final : intrusive_ref_counter { + struct method_state final { using invoke_impl = fixed_function)>; using invoke_error_impl = fixed_function)>; @@ -3988,7 +3791,7 @@ namespace meta_hpp::detail explicit method_state(method_index index, metadata_map metadata); }; - struct scope_state final : intrusive_ref_counter { + struct scope_state final { scope_index index; metadata_map metadata; @@ -4000,7 +3803,7 @@ namespace meta_hpp::detail explicit scope_state(scope_index index, metadata_map metadata); }; - struct variable_state final : intrusive_ref_counter { + struct variable_state final { using getter_impl = fixed_function; using setter_impl = fixed_function; using setter_error_impl = fixed_function; @@ -6256,7 +6059,7 @@ namespace meta_hpp::detail state.invoke_error = make_function_invoke_error(registry); state.arguments = make_function_arguments(); - return make_intrusive(std::move(state)); + return std::make_shared(std::move(state)); } } @@ -6792,7 +6595,7 @@ namespace meta_hpp::detail state.getter_error = make_member_getter_error(registry); state.setter_error = make_member_setter_error(registry); - return make_intrusive(std::move(state)); + return std::make_shared(std::move(state)); } } @@ -7091,7 +6894,7 @@ namespace meta_hpp::detail state.invoke_error = make_method_invoke_error(registry); state.arguments = make_method_arguments(); - return make_intrusive(std::move(state)); + return std::make_shared(std::move(state)); } } @@ -7456,7 +7259,7 @@ namespace meta_hpp::detail std::move(metadata), }; - return make_intrusive(std::move(state)); + return std::make_shared(std::move(state)); } } @@ -7655,7 +7458,7 @@ namespace meta_hpp::detail state.create_error = make_constructor_create_error(registry); state.arguments = make_constructor_arguments(); - return make_intrusive(std::move(state)); + return std::make_shared(std::move(state)); } } @@ -7847,7 +7650,7 @@ namespace meta_hpp::detail state.destroy_at = make_destructor_destroy_at(); state.destroy_error = make_destructor_destroy_error(registry); - return make_intrusive(std::move(state)); + return std::make_shared(std::move(state)); } } @@ -7992,7 +7795,7 @@ namespace meta_hpp::detail state.enum_value = uvalue{evalue}; state.underlying_value = uvalue{to_underlying(evalue)}; - return make_intrusive(std::move(state)); + return std::make_shared(std::move(state)); } } @@ -8150,7 +7953,7 @@ namespace meta_hpp::detail state.setter = make_variable_setter(registry, variable_ptr); state.setter_error = make_variable_setter_error(registry); - return make_intrusive(std::move(state)); + return std::make_shared(std::move(state)); } } @@ -8721,7 +8524,7 @@ namespace meta_hpp::detail scope_index{std::move(name)}, std::move(metadata), }; - return make_intrusive(std::move(state)); + return std::make_shared(std::move(state)); } } diff --git a/develop/untests/meta_base/intrusive_ptr_tests.cpp b/develop/untests/meta_base/intrusive_ptr_tests.cpp deleted file mode 100644 index 0cef996..0000000 --- a/develop/untests/meta_base/intrusive_ptr_tests.cpp +++ /dev/null @@ -1,222 +0,0 @@ -/******************************************************************************* - * This file is part of the "https://github.com/blackmatov/meta.hpp" - * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2021-2023, by Matvey Cherevko (blackmatov@gmail.com) - ******************************************************************************/ - -#include -#include - -namespace -{ - namespace meta = meta_hpp; - using meta::detail::intrusive_ptr; - using meta::detail::intrusive_ref_counter; - - struct obj_t final : intrusive_ref_counter { - int v{42}; - - obj_t() { ++ctor_counter; } - obj_t(int nv) : v{nv} { ++ctor_counter; } - ~obj_t() { ++dtor_counter; } - - inline static std::size_t ctor_counter{}; - inline static std::size_t dtor_counter{}; - }; -} - -TEST_CASE("meta/meta_base/intrusive_ptr") { - obj_t::ctor_counter = 0; - obj_t::dtor_counter = 0; - - SUBCASE("ctor/0") { - intrusive_ptr ptr; - CHECK_FALSE(ptr); - } - - SUBCASE("copy_ctor/0") { - intrusive_ptr ptr; - intrusive_ptr ptr2{ptr}; - CHECK_FALSE(ptr2); - } - - SUBCASE("move_ctor/0") { - intrusive_ptr ptr; - intrusive_ptr ptr2{std::move(ptr)}; - CHECK_FALSE(ptr2); - } - - SUBCASE("ctor/1") { - { - intrusive_ptr ptr{std::make_unique().release()}; - CHECK(ptr); - CHECK(ptr->get_use_count() == 1); - CHECK(ptr->v == 42); - CHECK(obj_t::ctor_counter == 1); - CHECK(obj_t::dtor_counter == 0); - } - CHECK(obj_t::ctor_counter == 1); - CHECK(obj_t::dtor_counter == 1); - } - - SUBCASE("copy_ctor/1") { - { - intrusive_ptr ptr{std::make_unique().release()}; - { - intrusive_ptr ptr2{ptr}; - CHECK(ptr); - CHECK(ptr2); - CHECK(ptr2->get_use_count() == 2); - CHECK(ptr2->v == 42); - } - CHECK(obj_t::ctor_counter == 1); - CHECK(obj_t::dtor_counter == 0); - } - CHECK(obj_t::ctor_counter == 1); - CHECK(obj_t::dtor_counter == 1); - } - - SUBCASE("move_ctor/1") { - { - intrusive_ptr ptr{std::make_unique().release()}; - { - intrusive_ptr ptr2{std::move(ptr)}; - CHECK_FALSE(ptr); - CHECK(ptr2); - CHECK(ptr2->get_use_count() == 1); - CHECK(ptr2->v == 42); - } - CHECK(obj_t::ctor_counter == 1); - CHECK(obj_t::dtor_counter == 1); - } - CHECK(obj_t::ctor_counter == 1); - CHECK(obj_t::dtor_counter == 1); - } - - SUBCASE("operator=/ptr") { - { - intrusive_ptr ptr1{std::make_unique().release()}; - ptr1 = std::make_unique().release(); - CHECK(obj_t::ctor_counter == 2); - CHECK(obj_t::dtor_counter == 1); - } - CHECK(obj_t::ctor_counter == 2); - CHECK(obj_t::dtor_counter == 2); - } - - SUBCASE("operator=/copy") { - { - intrusive_ptr ptr1{std::make_unique().release()}; - intrusive_ptr ptr2{std::make_unique().release()}; - ptr1 = ptr2; - CHECK(ptr1); - CHECK(ptr2); - CHECK(obj_t::ctor_counter == 2); - CHECK(obj_t::dtor_counter == 1); - } - CHECK(obj_t::ctor_counter == 2); - CHECK(obj_t::dtor_counter == 2); - } - - SUBCASE("operator=/move") { - { - intrusive_ptr ptr1{std::make_unique().release()}; - intrusive_ptr ptr2{std::make_unique().release()}; - ptr1 = std::move(ptr2); - CHECK(ptr1); - CHECK_FALSE(ptr2); - CHECK(obj_t::ctor_counter == 2); - CHECK(obj_t::dtor_counter == 1); - } - CHECK(obj_t::ctor_counter == 2); - CHECK(obj_t::dtor_counter == 2); - } - - SUBCASE("reset/0") { - intrusive_ptr ptr{std::make_unique().release()}; - ptr.reset(); - CHECK(obj_t::ctor_counter == 1); - CHECK(obj_t::dtor_counter == 1); - } - - SUBCASE("reset/1") { - { - intrusive_ptr ptr{std::make_unique().release()}; - ptr.reset(std::make_unique().release()); - CHECK(obj_t::ctor_counter == 2); - CHECK(obj_t::dtor_counter == 1); - } - CHECK(obj_t::ctor_counter == 2); - CHECK(obj_t::dtor_counter == 2); - } - - SUBCASE("get") { - intrusive_ptr ptr{std::make_unique().release()}; - CHECK(ptr.get()->v == 42); - CHECK(ptr->v == 42); - CHECK((*ptr).v == 42); - ptr.reset(); - CHECK_FALSE(ptr.get()); - } - - SUBCASE("release") { - obj_t* obj{}; - { - intrusive_ptr ptr{std::make_unique().release()}; - obj = ptr.release(); - CHECK_FALSE(ptr); - } - CHECK(obj_t::ctor_counter == 1); - CHECK(obj_t::dtor_counter == 0); - { - intrusive_ptr ptr2{obj, false}; - CHECK(ptr2->get_use_count() == 1); - } - CHECK(obj_t::ctor_counter == 1); - CHECK(obj_t::dtor_counter == 1); - } - - SUBCASE("swap") { - intrusive_ptr ptr1{std::make_unique(42).release()}; - intrusive_ptr ptr2{std::make_unique(21).release()}; - swap(ptr1, ptr2); - CHECK(ptr1->v == 21); - CHECK(ptr2->v == 42); - } - - SUBCASE("operator==/!=") { - intrusive_ptr ptr1{std::make_unique(42).release()}; - intrusive_ptr ptr1_copy{ptr1}; - intrusive_ptr ptr2{std::make_unique(42).release()}; - intrusive_ptr ptr3; - - CHECK(ptr1 == ptr1_copy); - CHECK(ptr1 == ptr1_copy.get()); - CHECK(ptr1_copy.get() == ptr1); - CHECK_FALSE(ptr1 == ptr2); - CHECK_FALSE(ptr1 == ptr3); - - CHECK_FALSE(ptr1 != ptr1_copy); - CHECK_FALSE(ptr1 != ptr1_copy.get()); - CHECK_FALSE(ptr1_copy.get() != ptr1); - CHECK(ptr1 != ptr2); - CHECK(ptr1 != ptr3); - - CHECK_FALSE(ptr1 == nullptr); - CHECK_FALSE(nullptr == ptr1); - CHECK(ptr1 != nullptr); - CHECK(nullptr != ptr1); - - CHECK(ptr3 == nullptr); - CHECK(nullptr == ptr3); - CHECK_FALSE(ptr3 != nullptr); - CHECK_FALSE(nullptr != ptr3); - } - - SUBCASE("hash") { - intrusive_ptr ptr1{}; - intrusive_ptr ptr2{meta::detail::make_intrusive(42)}; - CHECK(std::hash>{}(ptr1) == std::hash{}(ptr1.get())); - CHECK(std::hash>{}(ptr2) == std::hash{}(ptr2.get())); - } -} diff --git a/headers/meta.hpp/meta_base.hpp b/headers/meta.hpp/meta_base.hpp index 7bd1f3a..6312f06 100644 --- a/headers/meta.hpp/meta_base.hpp +++ b/headers/meta.hpp/meta_base.hpp @@ -16,7 +16,6 @@ #include "meta_base/hash_combiner.hpp" #include "meta_base/hashed_string.hpp" #include "meta_base/insert_or_assign.hpp" -#include "meta_base/intrusive_ptr.hpp" #include "meta_base/is_in_place_type.hpp" #include "meta_base/memory_buffer.hpp" #include "meta_base/noncopyable.hpp" @@ -97,15 +96,15 @@ namespace meta_hpp struct scope_state; struct variable_state; - using argument_state_ptr = intrusive_ptr; - using constructor_state_ptr = intrusive_ptr; - using destructor_state_ptr = intrusive_ptr; - using evalue_state_ptr = intrusive_ptr; - using function_state_ptr = intrusive_ptr; - using member_state_ptr = intrusive_ptr; - using method_state_ptr = intrusive_ptr; - using scope_state_ptr = intrusive_ptr; - using variable_state_ptr = intrusive_ptr; + using argument_state_ptr = std::shared_ptr; + using constructor_state_ptr = std::shared_ptr; + using destructor_state_ptr = std::shared_ptr; + using evalue_state_ptr = std::shared_ptr; + using function_state_ptr = std::shared_ptr; + using member_state_ptr = std::shared_ptr; + using method_state_ptr = std::shared_ptr; + using scope_state_ptr = std::shared_ptr; + using variable_state_ptr = std::shared_ptr; } template < typename T > diff --git a/headers/meta.hpp/meta_base/base.hpp b/headers/meta.hpp/meta_base/base.hpp index 072850f..ff84e40 100644 --- a/headers/meta.hpp/meta_base/base.hpp +++ b/headers/meta.hpp/meta_base/base.hpp @@ -14,7 +14,6 @@ #include #include -#include #include #include #include diff --git a/headers/meta.hpp/meta_base/intrusive_ptr.hpp b/headers/meta.hpp/meta_base/intrusive_ptr.hpp deleted file mode 100644 index 96db790..0000000 --- a/headers/meta.hpp/meta_base/intrusive_ptr.hpp +++ /dev/null @@ -1,206 +0,0 @@ -/******************************************************************************* - * This file is part of the "https://github.com/blackmatov/meta.hpp" - * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2021-2023, by Matvey Cherevko (blackmatov@gmail.com) - ******************************************************************************/ - -#pragma once - -#include "base.hpp" -#include "hash_combiner.hpp" - -namespace meta_hpp::detail -{ - template < typename Derived > - class intrusive_ref_counter; - - template < typename Derived > - void intrusive_ptr_add_ref(const intrusive_ref_counter* ptr); - - template < typename Derived > - void intrusive_ptr_release(const intrusive_ref_counter* ptr); - - template < typename Derived > - class intrusive_ref_counter { - public: - intrusive_ref_counter() = default; - - intrusive_ref_counter(intrusive_ref_counter&&) noexcept {} - - intrusive_ref_counter(const intrusive_ref_counter&) noexcept {} - - intrusive_ref_counter& operator=(intrusive_ref_counter&&) noexcept { - return *this; - } - - intrusive_ref_counter& operator=(const intrusive_ref_counter&) noexcept { - return *this; - } - - [[nodiscard]] std::size_t get_use_count() const noexcept { - return counter_.load(std::memory_order_acquire); - } - - protected: - ~intrusive_ref_counter() = default; - - private: - mutable std::atomic_size_t counter_{}; - friend void intrusive_ptr_add_ref(const intrusive_ref_counter* ptr); - friend void intrusive_ptr_release(const intrusive_ref_counter* ptr); - }; - - template < typename Derived > - void intrusive_ptr_add_ref(const intrusive_ref_counter* ptr) { - ptr->counter_.fetch_add(1, std::memory_order_acq_rel); - } - - template < typename Derived > - void intrusive_ptr_release(const intrusive_ref_counter* ptr) { - if ( ptr->counter_.fetch_sub(1, std::memory_order_acq_rel) == 1 ) { - // NOLINTNEXTLINE(*-owning-memory) - delete static_cast(ptr); - } - } -} - -namespace meta_hpp::detail -{ - template < typename T > - class intrusive_ptr final { - public: - intrusive_ptr() = default; - - ~intrusive_ptr() { - if ( ptr_ != nullptr ) { - intrusive_ptr_release(ptr_); - } - } - - intrusive_ptr(T* ptr, bool add_ref = true) - : ptr_{ptr} { - if ( ptr_ != nullptr && add_ref ) { - intrusive_ptr_add_ref(ptr_); - } - } - - intrusive_ptr(intrusive_ptr&& other) noexcept - : ptr_{other.ptr_} { - other.ptr_ = nullptr; - } - - intrusive_ptr(const intrusive_ptr& other) - : ptr_{other.ptr_} { - if ( ptr_ != nullptr ) { - intrusive_ptr_add_ref(ptr_); - } - } - - intrusive_ptr& operator=(T* ptr) noexcept { - intrusive_ptr{ptr}.swap(*this); - return *this; - } - - intrusive_ptr& operator=(intrusive_ptr&& other) noexcept { - intrusive_ptr{std::move(other)}.swap(*this); - return *this; - } - - intrusive_ptr& operator=(const intrusive_ptr& other) { - intrusive_ptr{other}.swap(*this); - return *this; - } - - void reset() { - intrusive_ptr{}.swap(*this); - } - - void reset(T* ptr) { - intrusive_ptr{ptr}.swap(*this); - } - - void reset(T* ptr, bool add_ref) { - intrusive_ptr{ptr, add_ref}.swap(*this); - } - - T* release() noexcept { - return std::exchange(ptr_, nullptr); - } - - [[nodiscard]] T* get() const noexcept { - return ptr_; - } - - [[nodiscard]] T& operator*() const noexcept { - return *ptr_; - } - - [[nodiscard]] T* operator->() const noexcept { - return ptr_; - } - - [[nodiscard]] explicit operator bool() const noexcept { - return ptr_ != nullptr; - } - - void swap(intrusive_ptr& other) noexcept { - ptr_ = std::exchange(other.ptr_, ptr_); - } - - [[nodiscard]] std::size_t get_hash() const noexcept { - return hash_combiner{}(ptr_); - } - - [[nodiscard]] bool operator==(const intrusive_ptr& other) const noexcept { - return ptr_ == other.ptr_; - } - - [[nodiscard]] std::strong_ordering operator<=>(const intrusive_ptr& other) const noexcept { - return ptr_ <=> other.ptr_; - } - - private: - T* ptr_{}; - }; - - template < typename T, typename... Args > - intrusive_ptr make_intrusive(Args&&... args) { - // NOLINTNEXTLINE(*-owning-memory) - return new T(std::forward(args)...); - } - - template < typename T > - void swap(intrusive_ptr& l, intrusive_ptr& r) noexcept { - return l.swap(r); - } - - template < typename T > - [[nodiscard]] bool operator==(const intrusive_ptr& l, const T* r) noexcept { - return l.get() == r; - } - - template < typename T > - [[nodiscard]] std::strong_ordering operator<=>(const intrusive_ptr& l, const T* r) noexcept { - return l.get() <=> r; - } - - template < typename T > - [[nodiscard]] bool operator==(const intrusive_ptr& l, std::nullptr_t) noexcept { - return l.get() == nullptr; - } - - template < typename T > - [[nodiscard]] std::strong_ordering operator<=>(const intrusive_ptr& l, std::nullptr_t) noexcept { - return l.get() <=> nullptr; - } -} - -namespace std -{ - template < typename T > - struct hash> { - size_t operator()(const meta_hpp::detail::intrusive_ptr& ip) const noexcept { - return ip.get_hash(); - } - }; -} diff --git a/headers/meta.hpp/meta_states.hpp b/headers/meta.hpp/meta_states.hpp index 8e82c38..31e0fe3 100644 --- a/headers/meta.hpp/meta_states.hpp +++ b/headers/meta.hpp/meta_states.hpp @@ -499,7 +499,7 @@ namespace meta_hpp namespace meta_hpp::detail { - struct argument_state final : intrusive_ref_counter { + struct argument_state final { argument_index index; metadata_map metadata; @@ -510,7 +510,7 @@ namespace meta_hpp::detail explicit argument_state(argument_index index, metadata_map metadata); }; - struct constructor_state final : intrusive_ref_counter { + struct constructor_state final { using create_impl = fixed_function)>; using create_at_impl = fixed_function)>; using create_error_impl = fixed_function)>; @@ -528,7 +528,7 @@ namespace meta_hpp::detail explicit constructor_state(constructor_index index, metadata_map metadata); }; - struct destructor_state final : intrusive_ref_counter { + struct destructor_state final { using destroy_impl = fixed_function; using destroy_at_impl = fixed_function; using destroy_error_impl = fixed_function; @@ -545,7 +545,7 @@ namespace meta_hpp::detail explicit destructor_state(destructor_index index, metadata_map metadata); }; - struct evalue_state final : intrusive_ref_counter { + struct evalue_state final { evalue_index index; metadata_map metadata; @@ -557,7 +557,7 @@ namespace meta_hpp::detail explicit evalue_state(evalue_index index, metadata_map metadata); }; - struct function_state final : intrusive_ref_counter { + struct function_state final { using invoke_impl = fixed_function)>; using invoke_error_impl = fixed_function)>; @@ -573,7 +573,7 @@ namespace meta_hpp::detail explicit function_state(function_index index, metadata_map metadata); }; - struct member_state final : intrusive_ref_counter { + struct member_state final { using getter_impl = fixed_function; using setter_impl = fixed_function; @@ -593,7 +593,7 @@ namespace meta_hpp::detail explicit member_state(member_index index, metadata_map metadata); }; - struct method_state final : intrusive_ref_counter { + struct method_state final { using invoke_impl = fixed_function)>; using invoke_error_impl = fixed_function)>; @@ -609,7 +609,7 @@ namespace meta_hpp::detail explicit method_state(method_index index, metadata_map metadata); }; - struct scope_state final : intrusive_ref_counter { + struct scope_state final { scope_index index; metadata_map metadata; @@ -621,7 +621,7 @@ namespace meta_hpp::detail explicit scope_state(scope_index index, metadata_map metadata); }; - struct variable_state final : intrusive_ref_counter { + struct variable_state final { using getter_impl = fixed_function; using setter_impl = fixed_function; using setter_error_impl = fixed_function; diff --git a/headers/meta.hpp/meta_states/argument.hpp b/headers/meta.hpp/meta_states/argument.hpp index 38b25d6..e13368f 100644 --- a/headers/meta.hpp/meta_states/argument.hpp +++ b/headers/meta.hpp/meta_states/argument.hpp @@ -26,7 +26,7 @@ namespace meta_hpp::detail std::move(metadata), }; - return make_intrusive(std::move(state)); + return std::make_shared(std::move(state)); } } diff --git a/headers/meta.hpp/meta_states/constructor.hpp b/headers/meta.hpp/meta_states/constructor.hpp index 3e5abcc..669e199 100644 --- a/headers/meta.hpp/meta_states/constructor.hpp +++ b/headers/meta.hpp/meta_states/constructor.hpp @@ -160,7 +160,7 @@ namespace meta_hpp::detail state.create_error = make_constructor_create_error(registry); state.arguments = make_constructor_arguments(); - return make_intrusive(std::move(state)); + return std::make_shared(std::move(state)); } } diff --git a/headers/meta.hpp/meta_states/destructor.hpp b/headers/meta.hpp/meta_states/destructor.hpp index 320781c..4519048 100644 --- a/headers/meta.hpp/meta_states/destructor.hpp +++ b/headers/meta.hpp/meta_states/destructor.hpp @@ -90,7 +90,7 @@ namespace meta_hpp::detail state.destroy_at = make_destructor_destroy_at(); state.destroy_error = make_destructor_destroy_error(registry); - return make_intrusive(std::move(state)); + return std::make_shared(std::move(state)); } } diff --git a/headers/meta.hpp/meta_states/evalue.hpp b/headers/meta.hpp/meta_states/evalue.hpp index 37f6299..9263373 100644 --- a/headers/meta.hpp/meta_states/evalue.hpp +++ b/headers/meta.hpp/meta_states/evalue.hpp @@ -30,7 +30,7 @@ namespace meta_hpp::detail state.enum_value = uvalue{evalue}; state.underlying_value = uvalue{to_underlying(evalue)}; - return make_intrusive(std::move(state)); + return std::make_shared(std::move(state)); } } diff --git a/headers/meta.hpp/meta_states/function.hpp b/headers/meta.hpp/meta_states/function.hpp index aae5632..930dd6d 100644 --- a/headers/meta.hpp/meta_states/function.hpp +++ b/headers/meta.hpp/meta_states/function.hpp @@ -130,7 +130,7 @@ namespace meta_hpp::detail state.invoke_error = make_function_invoke_error(registry); state.arguments = make_function_arguments(); - return make_intrusive(std::move(state)); + return std::make_shared(std::move(state)); } } diff --git a/headers/meta.hpp/meta_states/member.hpp b/headers/meta.hpp/meta_states/member.hpp index baf145a..4a9ec84 100644 --- a/headers/meta.hpp/meta_states/member.hpp +++ b/headers/meta.hpp/meta_states/member.hpp @@ -208,7 +208,7 @@ namespace meta_hpp::detail state.getter_error = make_member_getter_error(registry); state.setter_error = make_member_setter_error(registry); - return make_intrusive(std::move(state)); + return std::make_shared(std::move(state)); } } diff --git a/headers/meta.hpp/meta_states/method.hpp b/headers/meta.hpp/meta_states/method.hpp index bd5ff6a..fca76e7 100644 --- a/headers/meta.hpp/meta_states/method.hpp +++ b/headers/meta.hpp/meta_states/method.hpp @@ -142,7 +142,7 @@ namespace meta_hpp::detail state.invoke_error = make_method_invoke_error(registry); state.arguments = make_method_arguments(); - return make_intrusive(std::move(state)); + return std::make_shared(std::move(state)); } } diff --git a/headers/meta.hpp/meta_states/scope.hpp b/headers/meta.hpp/meta_states/scope.hpp index c3f3df4..b02f396 100644 --- a/headers/meta.hpp/meta_states/scope.hpp +++ b/headers/meta.hpp/meta_states/scope.hpp @@ -27,7 +27,7 @@ namespace meta_hpp::detail scope_index{std::move(name)}, std::move(metadata), }; - return make_intrusive(std::move(state)); + return std::make_shared(std::move(state)); } } diff --git a/headers/meta.hpp/meta_states/variable.hpp b/headers/meta.hpp/meta_states/variable.hpp index c05a9eb..29a1791 100644 --- a/headers/meta.hpp/meta_states/variable.hpp +++ b/headers/meta.hpp/meta_states/variable.hpp @@ -128,7 +128,7 @@ namespace meta_hpp::detail state.setter = make_variable_setter(registry, variable_ptr); state.setter_error = make_variable_setter_error(registry); - return make_intrusive(std::move(state)); + return std::make_shared(std::move(state)); } }