From b63143e19f74dbcf0415868c0ceaaa2d917c8421 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Fri, 9 Feb 2024 13:16:33 +0700 Subject: [PATCH] refactoring of type resolving --- ROADMAP.md | 4 +- develop/singles/headers/meta.hpp/meta_all.hpp | 613 ++++++++++-------- .../meta_shared_exe/meta_shared_tests.cpp | 26 +- .../untests/meta_issues/random_issue_2.cpp | 24 +- headers/meta.hpp/meta_base/base.hpp | 1 + headers/meta.hpp/meta_detail/base_info.hpp | 2 +- headers/meta.hpp/meta_detail/type_family.hpp | 168 ++++- .../meta.hpp/meta_detail/type_registry.hpp | 120 +--- headers/meta.hpp/meta_detail/type_sharing.hpp | 177 ++--- .../type_traits/nullptr_traits.hpp | 17 + .../meta_detail/type_traits/void_traits.hpp | 17 + .../meta_detail/value_utilities/uarg.hpp | 12 +- .../meta_detail/value_utilities/uinst.hpp | 8 +- .../meta_detail/value_utilities/utraits.hpp | 8 +- headers/meta.hpp/meta_details.hpp | 1 - headers/meta.hpp/meta_registry.hpp | 4 +- headers/meta.hpp/meta_states/argument.hpp | 2 +- headers/meta.hpp/meta_states/constructor.hpp | 2 +- headers/meta.hpp/meta_states/destructor.hpp | 2 +- headers/meta.hpp/meta_states/evalue.hpp | 2 +- headers/meta.hpp/meta_states/function.hpp | 2 +- headers/meta.hpp/meta_states/member.hpp | 2 +- headers/meta.hpp/meta_states/method.hpp | 2 +- headers/meta.hpp/meta_states/scope.hpp | 2 +- headers/meta.hpp/meta_states/variable.hpp | 2 +- headers/meta.hpp/meta_types.hpp | 27 +- headers/meta.hpp/meta_types/array_type.hpp | 4 +- headers/meta.hpp/meta_types/class_type.hpp | 10 +- .../meta.hpp/meta_types/constructor_type.hpp | 4 +- .../meta.hpp/meta_types/destructor_type.hpp | 4 +- headers/meta.hpp/meta_types/enum_type.hpp | 4 +- headers/meta.hpp/meta_types/function_type.hpp | 4 +- headers/meta.hpp/meta_types/member_type.hpp | 4 +- headers/meta.hpp/meta_types/method_type.hpp | 4 +- headers/meta.hpp/meta_types/nullptr_type.hpp | 4 +- headers/meta.hpp/meta_types/number_type.hpp | 4 +- headers/meta.hpp/meta_types/pointer_type.hpp | 4 +- .../meta.hpp/meta_types/reference_type.hpp | 4 +- headers/meta.hpp/meta_types/void_type.hpp | 4 +- headers/meta.hpp/meta_ucast/ucast.hpp | 2 +- 40 files changed, 767 insertions(+), 540 deletions(-) create mode 100644 headers/meta.hpp/meta_detail/type_traits/nullptr_traits.hpp create mode 100644 headers/meta.hpp/meta_detail/type_traits/void_traits.hpp diff --git a/ROADMAP.md b/ROADMAP.md index 43edcb5..3d497ec 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -2,9 +2,6 @@ ## Backlog -- type conversions -- fix all includes to work with the library more flexible -- remove ctor_type and dtor_type? - add variadic variant of invoking to meta_invoke ## Version 1.0 @@ -12,6 +9,7 @@ ## Version 2.0 - instance mapper +- type conversions - dynamic binds listener - static binds listener - dynamic type visitor diff --git a/develop/singles/headers/meta.hpp/meta_all.hpp b/develop/singles/headers/meta.hpp/meta_all.hpp index 5d3b74f..c813d77 100644 --- a/develop/singles/headers/meta.hpp/meta_all.hpp +++ b/develop/singles/headers/meta.hpp/meta_all.hpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -2189,6 +2190,12 @@ namespace meta_hpp::detail }; } +namespace meta_hpp::detail +{ + template < nullptr_kind Nullptr > + struct nullptr_traits {}; +} + namespace meta_hpp::detail { enum class number_flags : std::uint8_t { @@ -2317,6 +2324,12 @@ namespace meta_hpp::detail }; } +namespace meta_hpp::detail +{ + template < void_kind Void > + struct void_traits {}; +} + namespace meta_hpp::detail { struct type_data_base; @@ -2337,7 +2350,7 @@ namespace meta_hpp::detail namespace meta_hpp::detail { - template + template < type_family Type > struct type_traits; template < type_family Type > @@ -2355,83 +2368,247 @@ namespace meta_hpp::detail template <> struct type_traits { + using type = array_type; using data_ptr = array_type_data*; + using data_type = array_type_data; inline static constexpr type_kind kind{type_kind::array_}; }; template <> struct type_traits { + using type = class_type; using data_ptr = class_type_data*; + using data_type = class_type_data; inline static constexpr type_kind kind{type_kind::class_}; }; template <> struct type_traits { + using type = constructor_type; using data_ptr = constructor_type_data*; + using data_type = constructor_type_data; inline static constexpr type_kind kind{type_kind::constructor_}; }; template <> struct type_traits { + using type = destructor_type; using data_ptr = destructor_type_data*; + using data_type = destructor_type_data; inline static constexpr type_kind kind{type_kind::destructor_}; }; template <> struct type_traits { + using type = enum_type; using data_ptr = enum_type_data*; + using data_type = enum_type_data; inline static constexpr type_kind kind{type_kind::enum_}; }; template <> struct type_traits { + using type = function_type; using data_ptr = function_type_data*; + using data_type = function_type_data; inline static constexpr type_kind kind{type_kind::function_}; }; template <> struct type_traits { + using type = member_type; using data_ptr = member_type_data*; + using data_type = member_type_data; inline static constexpr type_kind kind{type_kind::member_}; }; template <> struct type_traits { + using type = method_type; using data_ptr = method_type_data*; + using data_type = method_type_data; inline static constexpr type_kind kind{type_kind::method_}; }; template <> struct type_traits { + using type = nullptr_type; using data_ptr = nullptr_type_data*; + using data_type = nullptr_type_data; inline static constexpr type_kind kind{type_kind::nullptr_}; }; template <> struct type_traits { + using type = number_type; using data_ptr = number_type_data*; + using data_type = number_type_data; inline static constexpr type_kind kind{type_kind::number_}; }; template <> struct type_traits { + using type = pointer_type; using data_ptr = pointer_type_data*; + using data_type = pointer_type_data; inline static constexpr type_kind kind{type_kind::pointer_}; }; template <> struct type_traits { + using type = reference_type; using data_ptr = reference_type_data*; + using data_type = reference_type_data; inline static constexpr type_kind kind{type_kind::reference_}; }; template <> struct type_traits { + using type = void_type; using data_ptr = void_type_data*; + using data_type = void_type_data; inline static constexpr type_kind kind{type_kind::void_}; }; } +namespace meta_hpp::detail +{ + template < typename T > + struct type_to_traits; + + template < typename T > + using type_to_traits_t = typename type_to_traits::type; + + template < array_kind T > + struct type_to_traits { + using type = array_traits; + }; + + template < class_kind T > + struct type_to_traits { + using type = class_traits; + }; + + template < enum_kind T > + struct type_to_traits { + using type = enum_traits; + }; + + template < function_kind T > + struct type_to_traits { + using type = function_traits; + }; + + template < member_pointer_kind T > + struct type_to_traits { + using type = member_traits; + }; + + template < method_pointer_kind T > + struct type_to_traits { + using type = method_traits; + }; + + template < nullptr_kind T > + struct type_to_traits { + using type = nullptr_traits; + }; + + template < number_kind T > + struct type_to_traits { + using type = number_traits; + }; + + template < pointer_kind T > + struct type_to_traits { + using type = pointer_traits; + }; + + template < reference_kind T > + struct type_to_traits { + using type = reference_traits; + }; + + template < void_kind T > + struct type_to_traits { + using type = void_traits; + }; +} + +namespace meta_hpp::detail +{ + template < typename Traits > + struct traits_to_type_traits; + + template < typename Traits > + using traits_to_type_traits_t = typename traits_to_type_traits::type; + + template < array_kind Array > + struct traits_to_type_traits> { + using type = type_traits; + }; + + template < class_kind Class > + struct traits_to_type_traits> { + using type = type_traits; + }; + + template < class_kind Class, typename... Args > + struct traits_to_type_traits> { + using type = type_traits; + }; + + template < class_kind Class > + struct traits_to_type_traits> { + using type = type_traits; + }; + + template < enum_kind Enum > + struct traits_to_type_traits> { + using type = type_traits; + }; + + template < function_kind Function > + struct traits_to_type_traits> { + using type = type_traits; + }; + + template < member_pointer_kind Member > + struct traits_to_type_traits> { + using type = type_traits; + }; + + template < method_pointer_kind Method > + struct traits_to_type_traits> { + using type = type_traits; + }; + + template < nullptr_kind Nullptr > + struct traits_to_type_traits> { + using type = type_traits; + }; + + template < number_kind Number > + struct traits_to_type_traits> { + using type = type_traits; + }; + + template < pointer_kind Pointer > + struct traits_to_type_traits> { + using type = type_traits; + }; + + template < reference_kind Reference > + struct traits_to_type_traits> { + using type = type_traits; + }; + + template < void_kind Void > + struct traits_to_type_traits> { + using type = type_traits; + }; +} + namespace meta_hpp { using detail::array_bitflags; @@ -3069,7 +3246,7 @@ namespace meta_hpp::detail // NOLINTEND(*-avoid-const-or-ref-data-members) template < array_kind Array > - explicit array_type_data(type_list); + explicit array_type_data(array_traits); }; struct class_type_data final : type_data_base { @@ -3104,7 +3281,7 @@ namespace meta_hpp::detail deep_upcasts_t deep_upcasts; template < class_kind Class > - explicit class_type_data(type_list); + explicit class_type_data(class_traits); }; struct constructor_type_data final : type_data_base { @@ -3115,7 +3292,7 @@ namespace meta_hpp::detail // NOLINTEND(*-avoid-const-or-ref-data-members) template < class_kind Class, typename... Args > - explicit constructor_type_data(type_list, type_list); + explicit constructor_type_data(constructor_traits); }; struct destructor_type_data final : type_data_base { @@ -3125,7 +3302,7 @@ namespace meta_hpp::detail // NOLINTEND(*-avoid-const-or-ref-data-members) template < class_kind Class > - explicit destructor_type_data(type_list); + explicit destructor_type_data(destructor_traits); }; struct enum_type_data final : type_data_base { @@ -3137,7 +3314,7 @@ namespace meta_hpp::detail evalue_list evalues; template < enum_kind Enum > - explicit enum_type_data(type_list); + explicit enum_type_data(enum_traits); }; struct function_type_data final : type_data_base { @@ -3148,7 +3325,7 @@ namespace meta_hpp::detail // NOLINTEND(*-avoid-const-or-ref-data-members) template < function_kind Function > - explicit function_type_data(type_list); + explicit function_type_data(function_traits); }; struct member_type_data final : type_data_base { @@ -3159,7 +3336,7 @@ namespace meta_hpp::detail // NOLINTEND(*-avoid-const-or-ref-data-members) template < member_pointer_kind Member > - explicit member_type_data(type_list); + explicit member_type_data(member_traits); }; struct method_type_data final : type_data_base { @@ -3171,12 +3348,12 @@ namespace meta_hpp::detail // NOLINTEND(*-avoid-const-or-ref-data-members) template < method_pointer_kind Method > - explicit method_type_data(type_list); + explicit method_type_data(method_traits); }; struct nullptr_type_data final : type_data_base { template < nullptr_kind Nullptr > - explicit nullptr_type_data(type_list); + explicit nullptr_type_data(nullptr_traits); }; struct number_type_data final : type_data_base { @@ -3187,7 +3364,7 @@ namespace meta_hpp::detail // NOLINTEND(*-avoid-const-or-ref-data-members) template < number_kind Number > - explicit number_type_data(type_list); + explicit number_type_data(number_traits); }; struct pointer_type_data final : type_data_base { @@ -3197,7 +3374,7 @@ namespace meta_hpp::detail // NOLINTEND(*-avoid-const-or-ref-data-members) template < pointer_kind Pointer > - explicit pointer_type_data(type_list); + explicit pointer_type_data(pointer_traits); }; struct reference_type_data final : type_data_base { @@ -3207,12 +3384,12 @@ namespace meta_hpp::detail // NOLINTEND(*-avoid-const-or-ref-data-members) template < reference_kind Reference > - explicit reference_type_data(type_list); + explicit reference_type_data(reference_traits); }; struct void_type_data final : type_data_base { template < void_kind Void > - explicit void_type_data(type_list); + explicit void_type_data(void_traits); }; } @@ -4417,129 +4594,39 @@ namespace meta_hpp::detail void for_each_type(F&& f) const { const locker lock; - // we use an index based for loop to avoid the iterator invalidation issues - // that can happen when adding a new type inside the loop - for ( std::size_t i{}; i < types_.size(); ++i ) { - std::invoke(f, types_[i]); + for ( auto&& type : types_ ) { + std::invoke(f, type); } } public: template < typename T > - [[nodiscard]] auto resolve_type() { - // clang-format off - if constexpr ( array_kind ) { return resolve_array_type(); } - if constexpr ( class_kind ) { return resolve_class_type(); } - if constexpr ( enum_kind ) { return resolve_enum_type(); } - if constexpr ( function_kind ) { return resolve_function_type(); } - if constexpr ( member_pointer_kind ) { return resolve_member_type(); } - if constexpr ( method_pointer_kind ) { return resolve_method_type(); } - if constexpr ( nullptr_kind ) { return resolve_nullptr_type(); } - if constexpr ( number_kind ) { return resolve_number_type(); } - if constexpr ( pointer_kind ) { return resolve_pointer_type(); } - if constexpr ( reference_kind ) { return resolve_reference_type(); } - if constexpr ( void_kind ) { return resolve_void_type(); } - // clang-format on + [[nodiscard]] auto resolve_by_type() { + return resolve_by_traits>>(); } - public: - template < array_kind Array > - [[nodiscard]] array_type resolve_array_type() { - using array_t = std::remove_cv_t; - return array_type{ensure_type(type_list{})}; - } + template < typename Traits > + [[nodiscard]] auto resolve_by_traits() { + using type_traits = traits_to_type_traits_t; - template < class_kind Class > - [[nodiscard]] class_type resolve_class_type() { - using class_t = std::remove_cv_t; - return class_type{ensure_type(type_list{})}; - } + static auto type_data_instance = [this]() { + auto new_data{std::make_unique(Traits{})}; - template < class_kind Class, typename... Args > - [[nodiscard]] constructor_type resolve_constructor_type() { - using class_t = std::remove_cv_t; - return constructor_type{ensure_type(type_list{}, type_list{})}; - } + const locker lock; + types_.emplace(new_data.get()); - template < class_kind Class > - [[nodiscard]] destructor_type resolve_destructor_type() { - using class_t = std::remove_cv_t; - return destructor_type{ensure_type(type_list{})}; - } + return new_data; + }(); - template < enum_kind Enum > - [[nodiscard]] enum_type resolve_enum_type() { - using enum_t = std::remove_cv_t; - return enum_type{ensure_type(type_list{})}; - } - - template < function_kind Function > - [[nodiscard]] function_type resolve_function_type() { - using function_t = std::remove_cv_t; - return function_type{ensure_type(type_list{})}; - } - - template < member_pointer_kind Member > - [[nodiscard]] member_type resolve_member_type() { - using member_t = std::remove_cv_t; - return member_type{ensure_type(type_list{})}; - } - - template < method_pointer_kind Method > - [[nodiscard]] method_type resolve_method_type() { - using method_t = std::remove_cv_t; - return method_type{ensure_type(type_list{})}; - } - - template < nullptr_kind Nullptr > - [[nodiscard]] nullptr_type resolve_nullptr_type() { - using nullptr_t = std::remove_cv_t; - return nullptr_type{ensure_type(type_list{})}; - } - - template < number_kind Number > - [[nodiscard]] number_type resolve_number_type() { - using number_t = std::remove_cv_t; - return number_type{ensure_type(type_list{})}; - } - - template < pointer_kind Pointer > - [[nodiscard]] pointer_type resolve_pointer_type() { - using pointer_t = std::remove_cv_t; - return pointer_type{ensure_type(type_list{})}; - } - - template < reference_kind Reference > - [[nodiscard]] reference_type resolve_reference_type() { - using reference_t = std::remove_cv_t; - return reference_type{ensure_type(type_list{})}; - } - - template < void_kind Void > - [[nodiscard]] void_type resolve_void_type() { - using void_t = std::remove_cv_t; - return void_type{ensure_type(type_list{})}; + return typename type_traits::type{type_data_instance.get()}; } private: type_registry() = default; - template < typename TypeData, typename... Args > - TypeData* ensure_type(Args&&... args) { - static auto data = [this](Args&&... captured_args) { - auto new_data{std::make_unique(META_HPP_FWD(captured_args)...)}; - - const locker lock; - types_.emplace_back(new_data.get()); - - return new_data; - }(META_HPP_FWD(args)...); - return data.get(); - } - private: std::recursive_mutex mutex_; - std::vector types_; + std::set> types_; }; } @@ -4579,7 +4666,7 @@ public: \ META_HPP_DETAIL_IGNORE_OVERRIDE_WARNINGS_PUSH() \ virtual ::meta_hpp::detail::poly_info meta_poly_info(::meta_hpp::detail::type_registry& registry) const { \ using self_type = std::remove_cvref_t; \ - return ::meta_hpp::detail::poly_info{.ptr = this, .type = registry.resolve_class_type()}; \ + return ::meta_hpp::detail::poly_info{.ptr = this, .type = registry.resolve_by_type()}; \ } \ META_HPP_DETAIL_IGNORE_OVERRIDE_WARNINGS_POP() \ private: @@ -4673,7 +4760,7 @@ namespace meta_hpp [[nodiscard]] auto resolve_type() { using namespace detail; type_registry& registry = type_registry::instance(); - return registry.resolve_type>(); + return registry.resolve_by_type>(); } template < typename T > @@ -4693,7 +4780,7 @@ namespace meta_hpp return detail::get_meta_poly_info(registry, from).type; } else { (void)from; - return registry.resolve_type(); + return registry.resolve_by_type(); } } } @@ -6035,8 +6122,8 @@ namespace meta_hpp::detail [[nodiscard]] To* pointer_upcast(type_registry& registry, From* ptr) { return static_cast(pointer_upcast( // ptr, - registry.resolve_type(), - registry.resolve_type() + registry.resolve_by_type(), + registry.resolve_by_type() )); } @@ -6044,8 +6131,8 @@ namespace meta_hpp::detail [[nodiscard]] const To* pointer_upcast(type_registry& registry, const From* ptr) { return static_cast(pointer_upcast( // ptr, - registry.resolve_type(), - registry.resolve_type() + registry.resolve_by_type(), + registry.resolve_by_type() )); } } @@ -6089,12 +6176,12 @@ namespace meta_hpp::detail template < arg_lvalue_ref_kind T > explicit uarg_base(type_registry& registry, type_list) : ref_type_{std::is_const_v> ? ref_types::const_lvalue : ref_types::lvalue} - , raw_type_{registry.resolve_type>()} {} + , raw_type_{registry.resolve_by_type>()} {} template < arg_rvalue_ref_kind T > explicit uarg_base(type_registry& registry, type_list) : ref_type_{std::is_const_v> ? ref_types::const_rvalue : ref_types::rvalue} - , raw_type_{registry.resolve_type>()} {} + , raw_type_{registry.resolve_by_type>()} {} explicit uarg_base(type_registry&, uvalue& v) : ref_type_{ref_types::lvalue} @@ -6201,7 +6288,7 @@ namespace meta_hpp::detail using to_raw_type = std::remove_cv_t; const any_type& from_type = get_raw_type(); - const pointer_type& to_type_ptr = registry.resolve_type(); + const pointer_type& to_type_ptr = registry.resolve_by_type(); if ( from_type.is_nullptr() ) { return true; @@ -6253,7 +6340,7 @@ namespace meta_hpp::detail ); const any_type& from_type = get_raw_type(); - const any_type& to_type = registry.resolve_type(); + const any_type& to_type = registry.resolve_by_type(); const auto is_convertible_to_ref = [this](type_list) { switch ( get_ref_type() ) { @@ -6308,7 +6395,7 @@ namespace meta_hpp::detail using to_raw_type = std::remove_cv_t; const any_type& from_type = get_raw_type(); - const pointer_type& to_type_ptr = registry.resolve_type(); + const pointer_type& to_type_ptr = registry.resolve_by_type(); if ( from_type.is_nullptr() ) { return static_cast(nullptr); @@ -6356,7 +6443,7 @@ namespace meta_hpp::detail ); const any_type& from_type = get_raw_type(); - const any_type& to_type = registry.resolve_type(); + const any_type& to_type = registry.resolve_by_type(); void* to_ptr = pointer_upcast(data_, from_type, to_type); META_HPP_ASSERT(to_ptr); @@ -6430,88 +6517,105 @@ namespace meta_hpp::detail namespace meta_hpp::detail { - template < typename > - struct shared_type_name; + namespace impl + { + template < typename Type > + struct shared_type; - template < type_kind, typename... > - struct shared_type_hash; -} + template < typename Traits > + struct shared_traits; -namespace meta_hpp::detail -{ - template < typename Type > - [[nodiscard]] constexpr std::size_t get_shared_hash() noexcept { - return shared_type_hash, Type>{}(); + template < typename Type > + concept shared_type_kind = requires { + { shared_type{} }; + }; + + template < typename Traits > + concept shared_traits_kind = requires { + { shared_traits{} }; + }; + + template < typename Type > + struct is_shared_type : std::bool_constant> {}; + + template < typename Traits > + struct is_shared_traits : std::bool_constant> {}; } -} -namespace meta_hpp::detail -{ - template < typename T > - struct is_shared_type : std::false_type {}; - - template < typename T > - concept shared_type_kind = is_shared_type>::value; -} - -namespace meta_hpp::detail -{ - template < type_kind, typename... > - struct shared_type_data_hash { + template < typename Traits > + struct shared_traits_hash { [[nodiscard]] std::size_t operator()(const void* type_data) const noexcept { return hash_composer{} << type_data; } }; - template < type_kind Kind, shared_type_kind... Types > - struct shared_type_data_hash { + template < impl::shared_traits_kind Traits > + struct shared_traits_hash { [[nodiscard]] std::size_t operator()(const void*) const noexcept { - return shared_type_hash{}(); + return impl::shared_traits{}(); } }; } -namespace meta_hpp::detail +namespace meta_hpp::detail::impl { - template < typename T > - requires requires { - { shared_type_name{}() }; - } - struct is_shared_type : std::true_type {}; - template < array_kind Array > requires shared_type_kind::data_type> - struct is_shared_type : std::true_type {}; + struct shared_type { + [[nodiscard]] constexpr std::size_t operator()() const noexcept { + return shared_traits>{}(); + } + }; template < function_kind Function > requires shared_type_kind::return_type> && type_list_and_v::argument_types> - struct is_shared_type : std::true_type {}; + struct shared_type { + [[nodiscard]] constexpr std::size_t operator()() const noexcept { + return shared_traits>{}(); + } + }; template < member_pointer_kind Member > requires shared_type_kind::class_type> && shared_type_kind::value_type> - struct is_shared_type : std::true_type {}; + struct shared_type { + [[nodiscard]] constexpr std::size_t operator()() const noexcept { + return shared_traits>{}(); + } + }; template < method_pointer_kind Method > requires shared_type_kind::class_type> && shared_type_kind::return_type> && type_list_and_v::argument_types> - struct is_shared_type : std::true_type {}; + struct shared_type { + [[nodiscard]] constexpr std::size_t operator()() const noexcept { + return shared_traits>{}(); + } + }; template < pointer_kind Pointer > requires shared_type_kind::data_type> - struct is_shared_type : std::true_type {}; + struct shared_type { + [[nodiscard]] constexpr std::size_t operator()() const noexcept { + return shared_traits>{}(); + } + }; template < reference_kind Reference > requires shared_type_kind::data_type> - struct is_shared_type : std::true_type {}; + struct shared_type { + [[nodiscard]] constexpr std::size_t operator()() const noexcept { + return shared_traits>{}(); + } + }; } -namespace meta_hpp::detail +namespace meta_hpp::detail::impl { template < shared_type_kind Array > - struct shared_type_hash { + struct shared_traits> { [[nodiscard]] constexpr std::size_t operator()() const noexcept { hash_composer hash{}; hash << type_kind::array_; @@ -6519,7 +6623,7 @@ namespace meta_hpp::detail using traits = array_traits; hash << traits::make_flags(); - hash << get_shared_hash(); + hash << shared_type{}(); hash << traits::extent; @@ -6528,7 +6632,7 @@ namespace meta_hpp::detail }; template < shared_type_kind Class > - struct shared_type_hash { + struct shared_traits> { [[nodiscard]] constexpr std::size_t operator()() const noexcept { hash_composer hash{}; hash << type_kind::class_; @@ -6536,14 +6640,14 @@ namespace meta_hpp::detail using traits = class_traits; hash << traits::make_flags(); - hash << shared_type_name{}(); + hash << shared_type{}(); return hash.hash; } }; template < shared_type_kind Class, shared_type_kind... Args > - struct shared_type_hash { + struct shared_traits> { [[nodiscard]] constexpr std::size_t operator()() const noexcept { hash_composer hash{}; hash << type_kind::constructor_; @@ -6551,10 +6655,10 @@ namespace meta_hpp::detail using traits = constructor_traits; hash << traits::make_flags(); - hash << get_shared_hash(); + hash << shared_type{}(); traits::argument_types::for_each([&hash]() { // - hash << get_shared_hash(); + hash << shared_type{}(); }); return hash.hash; @@ -6562,7 +6666,7 @@ namespace meta_hpp::detail }; template < shared_type_kind Class > - struct shared_type_hash { + struct shared_traits> { [[nodiscard]] constexpr std::size_t operator()() const noexcept { hash_composer hash{}; hash << type_kind::destructor_; @@ -6570,14 +6674,14 @@ namespace meta_hpp::detail using traits = destructor_traits; hash << traits::make_flags(); - hash << get_shared_hash(); + hash << shared_type{}(); return hash.hash; } }; template < shared_type_kind Enum > - struct shared_type_hash { + struct shared_traits> { [[nodiscard]] constexpr std::size_t operator()() const noexcept { hash_composer hash{}; hash << type_kind::enum_; @@ -6585,34 +6689,33 @@ namespace meta_hpp::detail using traits = enum_traits; hash << traits::make_flags(); - hash << shared_type_name{}(); + hash << shared_type{}(); return hash.hash; } }; template < shared_type_kind Function > - struct shared_type_hash { + struct shared_traits> { [[nodiscard]] constexpr std::size_t operator()() const noexcept { - hash_composer composer{}; - - composer << type_kind::function_; + hash_composer hash{}; + hash << type_kind::function_; using traits = function_traits; - composer << traits::make_flags(); + hash << traits::make_flags(); - composer << get_shared_hash(); + hash << shared_type{}(); - traits::argument_types::for_each([&composer]() { // - composer << get_shared_hash(); + traits::argument_types::for_each([&hash]() { // + hash << shared_type{}(); }); - return composer.hash; + return hash.hash; } }; template < shared_type_kind Member > - struct shared_type_hash { + struct shared_traits> { [[nodiscard]] constexpr std::size_t operator()() const noexcept { hash_composer hash{}; hash << type_kind::member_; @@ -6620,15 +6723,15 @@ namespace meta_hpp::detail using traits = member_traits; hash << traits::make_flags(); - hash << get_shared_hash(); - hash << get_shared_hash(); + hash << shared_type{}(); + hash << shared_type{}(); return hash.hash; } }; template < shared_type_kind Method > - struct shared_type_hash { + struct shared_traits> { [[nodiscard]] constexpr std::size_t operator()() const noexcept { hash_composer hash{}; hash << type_kind::method_; @@ -6636,11 +6739,11 @@ namespace meta_hpp::detail using traits = method_traits; hash << traits::make_flags(); - hash << get_shared_hash(); - hash << get_shared_hash(); + hash << shared_type{}(); + hash << shared_type{}(); traits::argument_types::for_each([&hash]() { // - hash << get_shared_hash(); + hash << shared_type{}(); }); return hash.hash; @@ -6648,19 +6751,19 @@ namespace meta_hpp::detail }; template < shared_type_kind Nullptr > - struct shared_type_hash { + struct shared_traits> { [[nodiscard]] constexpr std::size_t operator()() const noexcept { hash_composer hash{}; hash << type_kind::nullptr_; - hash << shared_type_name{}(); + hash << shared_type{}(); return hash.hash; } }; template < shared_type_kind Number > - struct shared_type_hash { + struct shared_traits> { [[nodiscard]] constexpr std::size_t operator()() const noexcept { hash_composer hash{}; hash << type_kind::number_; @@ -6668,14 +6771,14 @@ namespace meta_hpp::detail using traits = number_traits; hash << traits::make_flags(); - hash << shared_type_name{}(); + hash << shared_type{}(); return hash.hash; } }; template < shared_type_kind Pointer > - struct shared_type_hash { + struct shared_traits> { [[nodiscard]] constexpr std::size_t operator()() const noexcept { hash_composer hash{}; hash << type_kind::pointer_; @@ -6683,14 +6786,14 @@ namespace meta_hpp::detail using traits = pointer_traits; hash << traits::make_flags(); - hash << get_shared_hash(); + hash << shared_type{}(); return hash.hash; } }; template < shared_type_kind Reference > - struct shared_type_hash { + struct shared_traits> { [[nodiscard]] constexpr std::size_t operator()() const noexcept { hash_composer hash{}; hash << type_kind::reference_; @@ -6698,19 +6801,19 @@ namespace meta_hpp::detail using traits = reference_traits; hash << traits::make_flags(); - hash << get_shared_hash(); + hash << shared_type{}(); return hash.hash; } }; template < shared_type_kind Void > - struct shared_type_hash { + struct shared_traits> { [[nodiscard]] constexpr std::size_t operator()() const noexcept { hash_composer hash{}; hash << type_kind::void_; - hash << shared_type_name{}(); + hash << shared_type{}(); return hash.hash; } @@ -6718,10 +6821,10 @@ namespace meta_hpp::detail } #define META_HPP_DEFINE_SHARED_TYPE(Type, Name) \ - namespace meta_hpp::detail \ + namespace meta_hpp::detail::impl \ { \ template <> \ - struct shared_type_name { \ + struct shared_type { \ [[nodiscard]] constexpr std::size_t operator()() const noexcept { \ return hash_composer{} << std::string_view{Name}; \ } \ @@ -6776,8 +6879,8 @@ namespace meta_hpp::detail::function_type_data_impl namespace meta_hpp::detail { template < function_kind Function > - function_type_data::function_type_data(type_list) - : type_data_base{type_kind::function_, shared_type_data_hash{}(this)} + function_type_data::function_type_data(function_traits) + : type_data_base{type_kind::function_, shared_traits_hash>{}(this)} , flags{function_traits::make_flags()} , return_type{resolve_type::return_type>()} , argument_types(function_type_data_impl::make_argument_types()) {} @@ -6915,7 +7018,7 @@ namespace meta_hpp::detail type_registry& registry{type_registry::instance()}; function_state state{ - function_index{registry.resolve_type>(), std::move(name)}, + function_index{registry.resolve_by_type>(), std::move(name)}, std::move(metadata), }; @@ -7075,12 +7178,12 @@ namespace meta_hpp::detail template < inst_class_lvalue_ref_kind T > explicit uinst_base(type_registry& registry, type_list) : ref_type_{std::is_const_v> ? ref_types::const_lvalue : ref_types::lvalue} - , raw_type_{registry.resolve_type>()} {} + , raw_type_{registry.resolve_by_type>()} {} template < inst_class_rvalue_ref_kind T > explicit uinst_base(type_registry& registry, type_list) : ref_type_{std::is_const_v> ? ref_types::const_rvalue : ref_types::rvalue} - , raw_type_{registry.resolve_type>()} {} + , raw_type_{registry.resolve_by_type>()} {} explicit uinst_base(type_registry&, uvalue& v) : ref_type_{ref_types::lvalue} @@ -7187,7 +7290,7 @@ namespace meta_hpp::detail using inst_method = typename inst_traits::method_type; const any_type& from_type = get_raw_type(); - const any_type& to_type = registry.resolve_type(); + const any_type& to_type = registry.resolve_by_type(); if ( from_type.is_class() ) { const auto is_invocable = [this]() { @@ -7234,7 +7337,7 @@ namespace meta_hpp::detail using inst_class = std::remove_cv_t; const any_type& from_type = get_raw_type(); - const any_type& to_type = registry.resolve_type(); + const any_type& to_type = registry.resolve_by_type(); if ( from_type.is_class() && to_type.is_class() ) { void* to_ptr = pointer_upcast( // @@ -7286,8 +7389,8 @@ namespace meta_hpp::detail namespace meta_hpp::detail { template < member_pointer_kind Member > - member_type_data::member_type_data(type_list) - : type_data_base{type_kind::member_, shared_type_data_hash{}(this)} + member_type_data::member_type_data(member_traits) + : type_data_base{type_kind::member_, shared_traits_hash>{}(this)} , flags{member_traits::make_flags()} , owner_type{resolve_type::class_type>()} , value_type{resolve_type::value_type>()} {} @@ -7493,7 +7596,7 @@ namespace meta_hpp::detail type_registry& registry{type_registry::instance()}; member_state state{ - member_index{registry.resolve_type(), std::move(name)}, + member_index{registry.resolve_by_type(), std::move(name)}, std::move(metadata), }; @@ -7659,8 +7762,8 @@ namespace meta_hpp::detail::method_type_data_impl namespace meta_hpp::detail { template < method_pointer_kind Method > - method_type_data::method_type_data(type_list) - : type_data_base{type_kind::method_, shared_type_data_hash{}(this)} + method_type_data::method_type_data(method_traits) + : type_data_base{type_kind::method_, shared_traits_hash>{}(this)} , flags{method_traits::make_flags()} , owner_type{resolve_type::class_type>()} , return_type{resolve_type::return_type>()} @@ -7814,7 +7917,7 @@ namespace meta_hpp::detail type_registry& registry{type_registry::instance()}; method_state state{ - method_index{registry.resolve_type(), std::move(name)}, + method_index{registry.resolve_by_type(), std::move(name)}, std::move(metadata), }; @@ -8226,7 +8329,7 @@ namespace meta_hpp::detail type_registry& registry{type_registry::instance()}; argument_state state{ - argument_index{registry.resolve_type(), position}, + argument_index{registry.resolve_by_type(), position}, std::move(metadata), }; @@ -8273,8 +8376,8 @@ namespace meta_hpp::detail::constructor_type_data_impl namespace meta_hpp::detail { template < class_kind Class, typename... Args > - constructor_type_data::constructor_type_data(type_list, type_list) - : type_data_base{type_kind::constructor_, shared_type_data_hash{}(this)} + constructor_type_data::constructor_type_data(constructor_traits) + : type_data_base{type_kind::constructor_, shared_traits_hash>{}(this)} , flags{constructor_traits::make_flags()} , owner_type{resolve_type::class_type>()} , argument_types(constructor_type_data_impl::make_argument_types()) {} @@ -8441,7 +8544,7 @@ namespace meta_hpp::detail type_registry& registry{type_registry::instance()}; constructor_state state{ - constructor_index{registry.resolve_constructor_type()}, + constructor_index{registry.resolve_by_traits>()}, std::move(metadata), }; @@ -8608,8 +8711,8 @@ namespace meta_hpp namespace meta_hpp::detail { template < class_kind Class > - destructor_type_data::destructor_type_data(type_list) - : type_data_base{type_kind::destructor_, shared_type_data_hash{}(this)} + destructor_type_data::destructor_type_data(destructor_traits) + : type_data_base{type_kind::destructor_, shared_traits_hash>{}(this)} , flags{destructor_traits::make_flags()} , owner_type{resolve_type::class_type>()} {} } @@ -8694,7 +8797,7 @@ namespace meta_hpp::detail type_registry& registry{type_registry::instance()}; destructor_state state{ - destructor_index{registry.resolve_destructor_type()}, + destructor_index{registry.resolve_by_traits>()}, std::move(metadata), }; @@ -8777,8 +8880,8 @@ namespace meta_hpp namespace meta_hpp::detail { template < enum_kind Enum > - enum_type_data::enum_type_data(type_list) - : type_data_base{type_kind::enum_, shared_type_data_hash{}(this)} + enum_type_data::enum_type_data(enum_traits) + : type_data_base{type_kind::enum_, shared_traits_hash>{}(this)} , flags{enum_traits::make_flags()} , underlying_type{resolve_type::underlying_type>()} {} } @@ -8841,7 +8944,7 @@ namespace meta_hpp::detail type_registry& registry{type_registry::instance()}; evalue_state state{ - evalue_index{registry.resolve_type(), std::move(name)}, + evalue_index{registry.resolve_by_type(), std::move(name)}, std::move(metadata), }; @@ -8874,8 +8977,8 @@ namespace meta_hpp namespace meta_hpp::detail { template < pointer_kind Pointer > - pointer_type_data::pointer_type_data(type_list) - : type_data_base{type_kind::pointer_, shared_type_data_hash{}(this)} + pointer_type_data::pointer_type_data(pointer_traits) + : type_data_base{type_kind::pointer_, shared_traits_hash>{}(this)} , flags{pointer_traits::make_flags()} , data_type{resolve_type::data_type>()} {} } @@ -8998,7 +9101,7 @@ namespace meta_hpp::detail type_registry& registry{type_registry::instance()}; variable_state state{ - variable_index{registry.resolve_type(), std::move(name)}, + variable_index{registry.resolve_by_type(), std::move(name)}, std::move(metadata), }; @@ -9176,8 +9279,8 @@ namespace meta_hpp::detail::class_type_data_impl namespace meta_hpp::detail { template < class_kind Class > - class_type_data::class_type_data(type_list) - : type_data_base{type_kind::class_, shared_type_data_hash{}(this)} + class_type_data::class_type_data(class_traits) + : type_data_base{type_kind::class_, shared_traits_hash>{}(this)} , flags{class_traits::make_flags()} , size{class_traits::size} , align{class_traits::align} @@ -9468,7 +9571,7 @@ namespace meta_hpp template < typename... Args > constructor class_type::get_constructor_with() const noexcept { detail::type_registry& registry{detail::type_registry::instance()}; - return get_constructor_with({registry.resolve_type()...}); + return get_constructor_with({registry.resolve_by_type()...}); } template < typename Iter > @@ -9513,7 +9616,7 @@ namespace meta_hpp bool recursively ) const noexcept { detail::type_registry& registry{detail::type_registry::instance()}; - return get_function_with(name, {registry.resolve_type()...}, recursively); + return get_function_with(name, {registry.resolve_by_type()...}, recursively); } template < typename Iter > @@ -9573,7 +9676,7 @@ namespace meta_hpp bool recursively ) const noexcept { detail::type_registry& registry{detail::type_registry::instance()}; - return get_method_with(name, {registry.resolve_type()...}, recursively); + return get_method_with(name, {registry.resolve_by_type()...}, recursively); } template < typename Iter > @@ -9687,7 +9790,7 @@ namespace meta_hpp std::string_view name ) const noexcept { detail::type_registry& registry{detail::type_registry::instance()}; - return get_function_with(name, {registry.resolve_type()...}); + return get_function_with(name, {registry.resolve_by_type()...}); } template < typename Iter > @@ -9915,8 +10018,8 @@ namespace meta_hpp namespace meta_hpp::detail { template < array_kind Array > - array_type_data::array_type_data(type_list) - : type_data_base{type_kind::array_, shared_type_data_hash{}(this)} + array_type_data::array_type_data(array_traits) + : type_data_base{type_kind::array_, shared_traits_hash>{}(this)} , flags{array_traits::make_flags()} , extent{array_traits::extent} , data_type{resolve_type::data_type>()} {} @@ -9940,15 +10043,15 @@ namespace meta_hpp namespace meta_hpp::detail { template < nullptr_kind Nullptr > - nullptr_type_data::nullptr_type_data(type_list) - : type_data_base{type_kind::nullptr_, shared_type_data_hash{}(this)} {} + nullptr_type_data::nullptr_type_data(nullptr_traits) + : type_data_base{type_kind::nullptr_, shared_traits_hash>{}(this)} {} } namespace meta_hpp::detail { template < number_kind Number > - number_type_data::number_type_data(type_list) - : type_data_base{type_kind::number_, shared_type_data_hash{}(this)} + number_type_data::number_type_data(number_traits) + : type_data_base{type_kind::number_, shared_traits_hash>{}(this)} , flags{number_traits::make_flags()} , size{number_traits::size} , align{number_traits::align} {} @@ -9972,8 +10075,8 @@ namespace meta_hpp namespace meta_hpp::detail { template < reference_kind Reference > - reference_type_data::reference_type_data(type_list) - : type_data_base{type_kind::reference_, shared_type_data_hash{}(this)} + reference_type_data::reference_type_data(reference_traits) + : type_data_base{type_kind::reference_, shared_traits_hash>{}(this)} , flags{reference_traits::make_flags()} , data_type{resolve_type::data_type>()} {} } @@ -9992,8 +10095,8 @@ namespace meta_hpp namespace meta_hpp::detail { template < void_kind Void > - void_type_data::void_type_data(type_list) - : type_data_base{type_kind::void_, shared_type_data_hash{}(this)} {} + void_type_data::void_type_data(void_traits) + : type_data_base{type_kind::void_, shared_traits_hash>{}(this)} {} } namespace meta_hpp::detail @@ -10065,7 +10168,7 @@ namespace meta_hpp if constexpr ( std::is_void_v ) { return most_derived_object_ptr; } else { - const class_type& to_class_type = registry.resolve_class_type(); + const class_type& to_class_type = registry.resolve_by_type(); return static_cast(detail::pointer_upcast(most_derived_object_ptr, meta_info.type, to_class_type)); } } diff --git a/develop/unshared/meta_shared_exe/meta_shared_tests.cpp b/develop/unshared/meta_shared_exe/meta_shared_tests.cpp index 1b2681f..d9759ac 100644 --- a/develop/unshared/meta_shared_exe/meta_shared_tests.cpp +++ b/develop/unshared/meta_shared_exe/meta_shared_tests.cpp @@ -39,18 +39,20 @@ TEST_CASE("meta/meta_shared/tests") { REQUIRE(library_scope); SUBCASE("0") { - static_assert(meta::detail::shared_type_hash{}()); - static_assert(meta::detail::shared_type_hash{}()); - static_assert(meta::detail::shared_type_hash{}()); - static_assert(meta::detail::shared_type_hash{}()); - static_assert(meta::detail::shared_type_hash{}()); - static_assert(meta::detail::shared_type_hash{}()); - static_assert(meta::detail::shared_type_hash{}()); - static_assert(meta::detail::shared_type_hash{}()); - static_assert(meta::detail::shared_type_hash{}()); - static_assert(meta::detail::shared_type_hash{}()); - static_assert(meta::detail::shared_type_hash{}()); - static_assert(meta::detail::shared_type_hash{}()); + using namespace meta::detail; + using namespace meta::detail::impl; + static_assert(shared_traits>{}()); + static_assert(shared_traits>{}()); + static_assert(shared_traits>{}()); + static_assert(shared_traits>{}()); + static_assert(shared_traits>{}()); + static_assert(shared_traits>{}()); + static_assert(shared_traits>{}()); + static_assert(shared_traits>{}()); + static_assert(shared_traits>{}()); + static_assert(shared_traits>{}()); + static_assert(shared_traits>{}()); + static_assert(shared_traits>{}()); } SUBCASE("1") { diff --git a/develop/untests/meta_issues/random_issue_2.cpp b/develop/untests/meta_issues/random_issue_2.cpp index a3071d3..be6a19c 100644 --- a/develop/untests/meta_issues/random_issue_2.cpp +++ b/develop/untests/meta_issues/random_issue_2.cpp @@ -34,19 +34,19 @@ TEST_CASE("meta/meta_issues/random/2") { meta::detail::type_registry& r = meta::detail::type_registry::instance(); - CHECK(r.resolve_array_type() == r.resolve_array_type()); - CHECK(r.resolve_array_type() == r.resolve_array_type()); - CHECK(r.resolve_array_type() == r.resolve_array_type()); + CHECK(r.resolve_by_type() == r.resolve_by_type()); + CHECK(r.resolve_by_type() == r.resolve_by_type()); + CHECK(r.resolve_by_type() == r.resolve_by_type()); - CHECK(r.resolve_class_type() == r.resolve_class_type()); - CHECK(r.resolve_class_type() == r.resolve_class_type()); - CHECK(r.resolve_class_type() == r.resolve_class_type()); + CHECK(r.resolve_by_type() == r.resolve_by_type()); + CHECK(r.resolve_by_type() == r.resolve_by_type()); + CHECK(r.resolve_by_type() == r.resolve_by_type()); - CHECK(r.resolve_enum_type() == r.resolve_enum_type()); - CHECK(r.resolve_enum_type() == r.resolve_enum_type()); - CHECK(r.resolve_enum_type() == r.resolve_enum_type()); + CHECK(r.resolve_by_type() == r.resolve_by_type()); + CHECK(r.resolve_by_type() == r.resolve_by_type()); + CHECK(r.resolve_by_type() == r.resolve_by_type()); - CHECK(r.resolve_number_type() == r.resolve_number_type()); - CHECK(r.resolve_number_type() == r.resolve_number_type()); - CHECK(r.resolve_number_type() == r.resolve_number_type()); + CHECK(r.resolve_by_type() == r.resolve_by_type()); + CHECK(r.resolve_by_type() == r.resolve_by_type()); + CHECK(r.resolve_by_type() == r.resolve_by_type()); } diff --git a/headers/meta.hpp/meta_base/base.hpp b/headers/meta.hpp/meta_base/base.hpp index 97ba526..e3cd6df 100644 --- a/headers/meta.hpp/meta_base/base.hpp +++ b/headers/meta.hpp/meta_base/base.hpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include diff --git a/headers/meta.hpp/meta_detail/base_info.hpp b/headers/meta.hpp/meta_detail/base_info.hpp index 3cb5734..e2a5c44 100644 --- a/headers/meta.hpp/meta_detail/base_info.hpp +++ b/headers/meta.hpp/meta_detail/base_info.hpp @@ -47,7 +47,7 @@ public: \ META_HPP_DETAIL_IGNORE_OVERRIDE_WARNINGS_PUSH() \ virtual ::meta_hpp::detail::poly_info meta_poly_info(::meta_hpp::detail::type_registry& registry) const { \ using self_type = std::remove_cvref_t; \ - return ::meta_hpp::detail::poly_info{.ptr = this, .type = registry.resolve_class_type()}; \ + return ::meta_hpp::detail::poly_info{.ptr = this, .type = registry.resolve_by_type()}; \ } \ META_HPP_DETAIL_IGNORE_OVERRIDE_WARNINGS_POP() \ private: diff --git a/headers/meta.hpp/meta_detail/type_family.hpp b/headers/meta.hpp/meta_detail/type_family.hpp index b919b55..59dbcf8 100644 --- a/headers/meta.hpp/meta_detail/type_family.hpp +++ b/headers/meta.hpp/meta_detail/type_family.hpp @@ -18,9 +18,11 @@ #include "type_traits/function_traits.hpp" #include "type_traits/member_traits.hpp" #include "type_traits/method_traits.hpp" +#include "type_traits/nullptr_traits.hpp" #include "type_traits/number_traits.hpp" #include "type_traits/pointer_traits.hpp" #include "type_traits/reference_traits.hpp" +#include "type_traits/void_traits.hpp" namespace meta_hpp::detail { @@ -42,7 +44,7 @@ namespace meta_hpp::detail namespace meta_hpp::detail { - template + template < type_family Type > struct type_traits; template < type_family Type > @@ -60,79 +62,243 @@ namespace meta_hpp::detail template <> struct type_traits { + using type = array_type; using data_ptr = array_type_data*; + using data_type = array_type_data; inline static constexpr type_kind kind{type_kind::array_}; }; template <> struct type_traits { + using type = class_type; using data_ptr = class_type_data*; + using data_type = class_type_data; inline static constexpr type_kind kind{type_kind::class_}; }; template <> struct type_traits { + using type = constructor_type; using data_ptr = constructor_type_data*; + using data_type = constructor_type_data; inline static constexpr type_kind kind{type_kind::constructor_}; }; template <> struct type_traits { + using type = destructor_type; using data_ptr = destructor_type_data*; + using data_type = destructor_type_data; inline static constexpr type_kind kind{type_kind::destructor_}; }; template <> struct type_traits { + using type = enum_type; using data_ptr = enum_type_data*; + using data_type = enum_type_data; inline static constexpr type_kind kind{type_kind::enum_}; }; template <> struct type_traits { + using type = function_type; using data_ptr = function_type_data*; + using data_type = function_type_data; inline static constexpr type_kind kind{type_kind::function_}; }; template <> struct type_traits { + using type = member_type; using data_ptr = member_type_data*; + using data_type = member_type_data; inline static constexpr type_kind kind{type_kind::member_}; }; template <> struct type_traits { + using type = method_type; using data_ptr = method_type_data*; + using data_type = method_type_data; inline static constexpr type_kind kind{type_kind::method_}; }; template <> struct type_traits { + using type = nullptr_type; using data_ptr = nullptr_type_data*; + using data_type = nullptr_type_data; inline static constexpr type_kind kind{type_kind::nullptr_}; }; template <> struct type_traits { + using type = number_type; using data_ptr = number_type_data*; + using data_type = number_type_data; inline static constexpr type_kind kind{type_kind::number_}; }; template <> struct type_traits { + using type = pointer_type; using data_ptr = pointer_type_data*; + using data_type = pointer_type_data; inline static constexpr type_kind kind{type_kind::pointer_}; }; template <> struct type_traits { + using type = reference_type; using data_ptr = reference_type_data*; + using data_type = reference_type_data; inline static constexpr type_kind kind{type_kind::reference_}; }; template <> struct type_traits { + using type = void_type; using data_ptr = void_type_data*; + using data_type = void_type_data; inline static constexpr type_kind kind{type_kind::void_}; }; } + +namespace meta_hpp::detail +{ + template < typename T > + struct type_to_traits; + + template < typename T > + using type_to_traits_t = typename type_to_traits::type; + + template < array_kind T > + struct type_to_traits { + using type = array_traits; + }; + + template < class_kind T > + struct type_to_traits { + using type = class_traits; + }; + + template < enum_kind T > + struct type_to_traits { + using type = enum_traits; + }; + + template < function_kind T > + struct type_to_traits { + using type = function_traits; + }; + + template < member_pointer_kind T > + struct type_to_traits { + using type = member_traits; + }; + + template < method_pointer_kind T > + struct type_to_traits { + using type = method_traits; + }; + + template < nullptr_kind T > + struct type_to_traits { + using type = nullptr_traits; + }; + + template < number_kind T > + struct type_to_traits { + using type = number_traits; + }; + + template < pointer_kind T > + struct type_to_traits { + using type = pointer_traits; + }; + + template < reference_kind T > + struct type_to_traits { + using type = reference_traits; + }; + + template < void_kind T > + struct type_to_traits { + using type = void_traits; + }; +} + +namespace meta_hpp::detail +{ + template < typename Traits > + struct traits_to_type_traits; + + template < typename Traits > + using traits_to_type_traits_t = typename traits_to_type_traits::type; + + template < array_kind Array > + struct traits_to_type_traits> { + using type = type_traits; + }; + + template < class_kind Class > + struct traits_to_type_traits> { + using type = type_traits; + }; + + template < class_kind Class, typename... Args > + struct traits_to_type_traits> { + using type = type_traits; + }; + + template < class_kind Class > + struct traits_to_type_traits> { + using type = type_traits; + }; + + template < enum_kind Enum > + struct traits_to_type_traits> { + using type = type_traits; + }; + + template < function_kind Function > + struct traits_to_type_traits> { + using type = type_traits; + }; + + template < member_pointer_kind Member > + struct traits_to_type_traits> { + using type = type_traits; + }; + + template < method_pointer_kind Method > + struct traits_to_type_traits> { + using type = type_traits; + }; + + template < nullptr_kind Nullptr > + struct traits_to_type_traits> { + using type = type_traits; + }; + + template < number_kind Number > + struct traits_to_type_traits> { + using type = type_traits; + }; + + template < pointer_kind Pointer > + struct traits_to_type_traits> { + using type = type_traits; + }; + + template < reference_kind Reference > + struct traits_to_type_traits> { + using type = type_traits; + }; + + template < void_kind Void > + struct traits_to_type_traits> { + using type = type_traits; + }; +} diff --git a/headers/meta.hpp/meta_detail/type_registry.hpp b/headers/meta.hpp/meta_detail/type_registry.hpp index 4fe8f7a..ba3302a 100644 --- a/headers/meta.hpp/meta_detail/type_registry.hpp +++ b/headers/meta.hpp/meta_detail/type_registry.hpp @@ -41,128 +41,38 @@ namespace meta_hpp::detail void for_each_type(F&& f) const { const locker lock; - // we use an index based for loop to avoid the iterator invalidation issues - // that can happen when adding a new type inside the loop - for ( std::size_t i{}; i < types_.size(); ++i ) { - std::invoke(f, types_[i]); + for ( auto&& type : types_ ) { + std::invoke(f, type); } } public: template < typename T > - [[nodiscard]] auto resolve_type() { - // clang-format off - if constexpr ( array_kind ) { return resolve_array_type(); } - if constexpr ( class_kind ) { return resolve_class_type(); } - if constexpr ( enum_kind ) { return resolve_enum_type(); } - if constexpr ( function_kind ) { return resolve_function_type(); } - if constexpr ( member_pointer_kind ) { return resolve_member_type(); } - if constexpr ( method_pointer_kind ) { return resolve_method_type(); } - if constexpr ( nullptr_kind ) { return resolve_nullptr_type(); } - if constexpr ( number_kind ) { return resolve_number_type(); } - if constexpr ( pointer_kind ) { return resolve_pointer_type(); } - if constexpr ( reference_kind ) { return resolve_reference_type(); } - if constexpr ( void_kind ) { return resolve_void_type(); } - // clang-format on + [[nodiscard]] auto resolve_by_type() { + return resolve_by_traits>>(); } - public: - template < array_kind Array > - [[nodiscard]] array_type resolve_array_type() { - using array_t = std::remove_cv_t; - return array_type{ensure_type(type_list{})}; - } + template < typename Traits > + [[nodiscard]] auto resolve_by_traits() { + using type_traits = traits_to_type_traits_t; - template < class_kind Class > - [[nodiscard]] class_type resolve_class_type() { - using class_t = std::remove_cv_t; - return class_type{ensure_type(type_list{})}; - } + static auto type_data_instance = [this]() { + auto new_data{std::make_unique(Traits{})}; - template < class_kind Class, typename... Args > - [[nodiscard]] constructor_type resolve_constructor_type() { - using class_t = std::remove_cv_t; - return constructor_type{ensure_type(type_list{}, type_list{})}; - } + const locker lock; + types_.emplace(new_data.get()); - template < class_kind Class > - [[nodiscard]] destructor_type resolve_destructor_type() { - using class_t = std::remove_cv_t; - return destructor_type{ensure_type(type_list{})}; - } + return new_data; + }(); - template < enum_kind Enum > - [[nodiscard]] enum_type resolve_enum_type() { - using enum_t = std::remove_cv_t; - return enum_type{ensure_type(type_list{})}; - } - - template < function_kind Function > - [[nodiscard]] function_type resolve_function_type() { - using function_t = std::remove_cv_t; - return function_type{ensure_type(type_list{})}; - } - - template < member_pointer_kind Member > - [[nodiscard]] member_type resolve_member_type() { - using member_t = std::remove_cv_t; - return member_type{ensure_type(type_list{})}; - } - - template < method_pointer_kind Method > - [[nodiscard]] method_type resolve_method_type() { - using method_t = std::remove_cv_t; - return method_type{ensure_type(type_list{})}; - } - - template < nullptr_kind Nullptr > - [[nodiscard]] nullptr_type resolve_nullptr_type() { - using nullptr_t = std::remove_cv_t; - return nullptr_type{ensure_type(type_list{})}; - } - - template < number_kind Number > - [[nodiscard]] number_type resolve_number_type() { - using number_t = std::remove_cv_t; - return number_type{ensure_type(type_list{})}; - } - - template < pointer_kind Pointer > - [[nodiscard]] pointer_type resolve_pointer_type() { - using pointer_t = std::remove_cv_t; - return pointer_type{ensure_type(type_list{})}; - } - - template < reference_kind Reference > - [[nodiscard]] reference_type resolve_reference_type() { - using reference_t = std::remove_cv_t; - return reference_type{ensure_type(type_list{})}; - } - - template < void_kind Void > - [[nodiscard]] void_type resolve_void_type() { - using void_t = std::remove_cv_t; - return void_type{ensure_type(type_list{})}; + return typename type_traits::type{type_data_instance.get()}; } private: type_registry() = default; - template < typename TypeData, typename... Args > - TypeData* ensure_type(Args&&... args) { - static auto data = [this](Args&&... captured_args) { - auto new_data{std::make_unique(META_HPP_FWD(captured_args)...)}; - - const locker lock; - types_.emplace_back(new_data.get()); - - return new_data; - }(META_HPP_FWD(args)...); - return data.get(); - } - private: std::recursive_mutex mutex_; - std::vector types_; + std::set> types_; }; } diff --git a/headers/meta.hpp/meta_detail/type_sharing.hpp b/headers/meta.hpp/meta_detail/type_sharing.hpp index fe88476..143cfbc 100644 --- a/headers/meta.hpp/meta_detail/type_sharing.hpp +++ b/headers/meta.hpp/meta_detail/type_sharing.hpp @@ -9,92 +9,108 @@ #include "../meta_base.hpp" #include "type_family.hpp" -#include "type_kinds.hpp" namespace meta_hpp::detail { - template < typename > - struct shared_type_name; + namespace impl + { + template < typename Type > + struct shared_type; - template < type_kind, typename... > - struct shared_type_hash; -} + template < typename Traits > + struct shared_traits; -namespace meta_hpp::detail -{ - template < typename Type > - [[nodiscard]] constexpr std::size_t get_shared_hash() noexcept { - return shared_type_hash, Type>{}(); + template < typename Type > + concept shared_type_kind = requires { + { shared_type{} }; + }; + + template < typename Traits > + concept shared_traits_kind = requires { + { shared_traits{} }; + }; + + template < typename Type > + struct is_shared_type : std::bool_constant> {}; + + template < typename Traits > + struct is_shared_traits : std::bool_constant> {}; } -} -namespace meta_hpp::detail -{ - template < typename T > - struct is_shared_type : std::false_type {}; - - template < typename T > - concept shared_type_kind = is_shared_type>::value; -} - -namespace meta_hpp::detail -{ - template < type_kind, typename... > - struct shared_type_data_hash { + template < typename Traits > + struct shared_traits_hash { [[nodiscard]] std::size_t operator()(const void* type_data) const noexcept { return hash_composer{} << type_data; } }; - template < type_kind Kind, shared_type_kind... Types > - struct shared_type_data_hash { + template < impl::shared_traits_kind Traits > + struct shared_traits_hash { [[nodiscard]] std::size_t operator()(const void*) const noexcept { - return shared_type_hash{}(); + return impl::shared_traits{}(); } }; } -namespace meta_hpp::detail +namespace meta_hpp::detail::impl { - template < typename T > - requires requires { - { shared_type_name{}() }; - } - struct is_shared_type : std::true_type {}; - template < array_kind Array > requires shared_type_kind::data_type> - struct is_shared_type : std::true_type {}; + struct shared_type { + [[nodiscard]] constexpr std::size_t operator()() const noexcept { + return shared_traits>{}(); + } + }; template < function_kind Function > requires shared_type_kind::return_type> && type_list_and_v::argument_types> - struct is_shared_type : std::true_type {}; + struct shared_type { + [[nodiscard]] constexpr std::size_t operator()() const noexcept { + return shared_traits>{}(); + } + }; template < member_pointer_kind Member > requires shared_type_kind::class_type> && shared_type_kind::value_type> - struct is_shared_type : std::true_type {}; + struct shared_type { + [[nodiscard]] constexpr std::size_t operator()() const noexcept { + return shared_traits>{}(); + } + }; template < method_pointer_kind Method > requires shared_type_kind::class_type> && shared_type_kind::return_type> && type_list_and_v::argument_types> - struct is_shared_type : std::true_type {}; + struct shared_type { + [[nodiscard]] constexpr std::size_t operator()() const noexcept { + return shared_traits>{}(); + } + }; template < pointer_kind Pointer > requires shared_type_kind::data_type> - struct is_shared_type : std::true_type {}; + struct shared_type { + [[nodiscard]] constexpr std::size_t operator()() const noexcept { + return shared_traits>{}(); + } + }; template < reference_kind Reference > requires shared_type_kind::data_type> - struct is_shared_type : std::true_type {}; + struct shared_type { + [[nodiscard]] constexpr std::size_t operator()() const noexcept { + return shared_traits>{}(); + } + }; } -namespace meta_hpp::detail +namespace meta_hpp::detail::impl { template < shared_type_kind Array > - struct shared_type_hash { + struct shared_traits> { [[nodiscard]] constexpr std::size_t operator()() const noexcept { hash_composer hash{}; hash << type_kind::array_; @@ -102,7 +118,7 @@ namespace meta_hpp::detail using traits = array_traits; hash << traits::make_flags(); - hash << get_shared_hash(); + hash << shared_type{}(); hash << traits::extent; @@ -111,7 +127,7 @@ namespace meta_hpp::detail }; template < shared_type_kind Class > - struct shared_type_hash { + struct shared_traits> { [[nodiscard]] constexpr std::size_t operator()() const noexcept { hash_composer hash{}; hash << type_kind::class_; @@ -119,14 +135,14 @@ namespace meta_hpp::detail using traits = class_traits; hash << traits::make_flags(); - hash << shared_type_name{}(); + hash << shared_type{}(); return hash.hash; } }; template < shared_type_kind Class, shared_type_kind... Args > - struct shared_type_hash { + struct shared_traits> { [[nodiscard]] constexpr std::size_t operator()() const noexcept { hash_composer hash{}; hash << type_kind::constructor_; @@ -134,10 +150,10 @@ namespace meta_hpp::detail using traits = constructor_traits; hash << traits::make_flags(); - hash << get_shared_hash(); + hash << shared_type{}(); traits::argument_types::for_each([&hash]() { // - hash << get_shared_hash(); + hash << shared_type{}(); }); return hash.hash; @@ -145,7 +161,7 @@ namespace meta_hpp::detail }; template < shared_type_kind Class > - struct shared_type_hash { + struct shared_traits> { [[nodiscard]] constexpr std::size_t operator()() const noexcept { hash_composer hash{}; hash << type_kind::destructor_; @@ -153,14 +169,14 @@ namespace meta_hpp::detail using traits = destructor_traits; hash << traits::make_flags(); - hash << get_shared_hash(); + hash << shared_type{}(); return hash.hash; } }; template < shared_type_kind Enum > - struct shared_type_hash { + struct shared_traits> { [[nodiscard]] constexpr std::size_t operator()() const noexcept { hash_composer hash{}; hash << type_kind::enum_; @@ -168,34 +184,33 @@ namespace meta_hpp::detail using traits = enum_traits; hash << traits::make_flags(); - hash << shared_type_name{}(); + hash << shared_type{}(); return hash.hash; } }; template < shared_type_kind Function > - struct shared_type_hash { + struct shared_traits> { [[nodiscard]] constexpr std::size_t operator()() const noexcept { - hash_composer composer{}; - - composer << type_kind::function_; + hash_composer hash{}; + hash << type_kind::function_; using traits = function_traits; - composer << traits::make_flags(); + hash << traits::make_flags(); - composer << get_shared_hash(); + hash << shared_type{}(); - traits::argument_types::for_each([&composer]() { // - composer << get_shared_hash(); + traits::argument_types::for_each([&hash]() { // + hash << shared_type{}(); }); - return composer.hash; + return hash.hash; } }; template < shared_type_kind Member > - struct shared_type_hash { + struct shared_traits> { [[nodiscard]] constexpr std::size_t operator()() const noexcept { hash_composer hash{}; hash << type_kind::member_; @@ -203,15 +218,15 @@ namespace meta_hpp::detail using traits = member_traits; hash << traits::make_flags(); - hash << get_shared_hash(); - hash << get_shared_hash(); + hash << shared_type{}(); + hash << shared_type{}(); return hash.hash; } }; template < shared_type_kind Method > - struct shared_type_hash { + struct shared_traits> { [[nodiscard]] constexpr std::size_t operator()() const noexcept { hash_composer hash{}; hash << type_kind::method_; @@ -219,11 +234,11 @@ namespace meta_hpp::detail using traits = method_traits; hash << traits::make_flags(); - hash << get_shared_hash(); - hash << get_shared_hash(); + hash << shared_type{}(); + hash << shared_type{}(); traits::argument_types::for_each([&hash]() { // - hash << get_shared_hash(); + hash << shared_type{}(); }); return hash.hash; @@ -231,19 +246,19 @@ namespace meta_hpp::detail }; template < shared_type_kind Nullptr > - struct shared_type_hash { + struct shared_traits> { [[nodiscard]] constexpr std::size_t operator()() const noexcept { hash_composer hash{}; hash << type_kind::nullptr_; - hash << shared_type_name{}(); + hash << shared_type{}(); return hash.hash; } }; template < shared_type_kind Number > - struct shared_type_hash { + struct shared_traits> { [[nodiscard]] constexpr std::size_t operator()() const noexcept { hash_composer hash{}; hash << type_kind::number_; @@ -251,14 +266,14 @@ namespace meta_hpp::detail using traits = number_traits; hash << traits::make_flags(); - hash << shared_type_name{}(); + hash << shared_type{}(); return hash.hash; } }; template < shared_type_kind Pointer > - struct shared_type_hash { + struct shared_traits> { [[nodiscard]] constexpr std::size_t operator()() const noexcept { hash_composer hash{}; hash << type_kind::pointer_; @@ -266,14 +281,14 @@ namespace meta_hpp::detail using traits = pointer_traits; hash << traits::make_flags(); - hash << get_shared_hash(); + hash << shared_type{}(); return hash.hash; } }; template < shared_type_kind Reference > - struct shared_type_hash { + struct shared_traits> { [[nodiscard]] constexpr std::size_t operator()() const noexcept { hash_composer hash{}; hash << type_kind::reference_; @@ -281,19 +296,19 @@ namespace meta_hpp::detail using traits = reference_traits; hash << traits::make_flags(); - hash << get_shared_hash(); + hash << shared_type{}(); return hash.hash; } }; template < shared_type_kind Void > - struct shared_type_hash { + struct shared_traits> { [[nodiscard]] constexpr std::size_t operator()() const noexcept { hash_composer hash{}; hash << type_kind::void_; - hash << shared_type_name{}(); + hash << shared_type{}(); return hash.hash; } @@ -301,10 +316,10 @@ namespace meta_hpp::detail } #define META_HPP_DEFINE_SHARED_TYPE(Type, Name) \ - namespace meta_hpp::detail \ + namespace meta_hpp::detail::impl \ { \ template <> \ - struct shared_type_name { \ + struct shared_type { \ [[nodiscard]] constexpr std::size_t operator()() const noexcept { \ return hash_composer{} << std::string_view{Name}; \ } \ diff --git a/headers/meta.hpp/meta_detail/type_traits/nullptr_traits.hpp b/headers/meta.hpp/meta_detail/type_traits/nullptr_traits.hpp new file mode 100644 index 0000000..91555c6 --- /dev/null +++ b/headers/meta.hpp/meta_detail/type_traits/nullptr_traits.hpp @@ -0,0 +1,17 @@ +/******************************************************************************* + * 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-2024, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#pragma once + +#include "../../meta_base.hpp" + +#include "../type_kinds.hpp" + +namespace meta_hpp::detail +{ + template < nullptr_kind Nullptr > + struct nullptr_traits {}; +} diff --git a/headers/meta.hpp/meta_detail/type_traits/void_traits.hpp b/headers/meta.hpp/meta_detail/type_traits/void_traits.hpp new file mode 100644 index 0000000..e7a33cd --- /dev/null +++ b/headers/meta.hpp/meta_detail/type_traits/void_traits.hpp @@ -0,0 +1,17 @@ +/******************************************************************************* + * 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-2024, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#pragma once + +#include "../../meta_base.hpp" + +#include "../type_kinds.hpp" + +namespace meta_hpp::detail +{ + template < void_kind Void > + struct void_traits {}; +} diff --git a/headers/meta.hpp/meta_detail/value_utilities/uarg.hpp b/headers/meta.hpp/meta_detail/value_utilities/uarg.hpp index cc6fb91..fe7c7eb 100644 --- a/headers/meta.hpp/meta_detail/value_utilities/uarg.hpp +++ b/headers/meta.hpp/meta_detail/value_utilities/uarg.hpp @@ -52,12 +52,12 @@ namespace meta_hpp::detail template < arg_lvalue_ref_kind T > explicit uarg_base(type_registry& registry, type_list) : ref_type_{std::is_const_v> ? ref_types::const_lvalue : ref_types::lvalue} - , raw_type_{registry.resolve_type>()} {} + , raw_type_{registry.resolve_by_type>()} {} template < arg_rvalue_ref_kind T > explicit uarg_base(type_registry& registry, type_list) : ref_type_{std::is_const_v> ? ref_types::const_rvalue : ref_types::rvalue} - , raw_type_{registry.resolve_type>()} {} + , raw_type_{registry.resolve_by_type>()} {} explicit uarg_base(type_registry&, uvalue& v) : ref_type_{ref_types::lvalue} @@ -164,7 +164,7 @@ namespace meta_hpp::detail using to_raw_type = std::remove_cv_t; const any_type& from_type = get_raw_type(); - const pointer_type& to_type_ptr = registry.resolve_type(); + const pointer_type& to_type_ptr = registry.resolve_by_type(); if ( from_type.is_nullptr() ) { return true; @@ -216,7 +216,7 @@ namespace meta_hpp::detail ); const any_type& from_type = get_raw_type(); - const any_type& to_type = registry.resolve_type(); + const any_type& to_type = registry.resolve_by_type(); const auto is_convertible_to_ref = [this](type_list) { switch ( get_ref_type() ) { @@ -271,7 +271,7 @@ namespace meta_hpp::detail using to_raw_type = std::remove_cv_t; const any_type& from_type = get_raw_type(); - const pointer_type& to_type_ptr = registry.resolve_type(); + const pointer_type& to_type_ptr = registry.resolve_by_type(); if ( from_type.is_nullptr() ) { return static_cast(nullptr); @@ -319,7 +319,7 @@ namespace meta_hpp::detail ); const any_type& from_type = get_raw_type(); - const any_type& to_type = registry.resolve_type(); + const any_type& to_type = registry.resolve_by_type(); void* to_ptr = pointer_upcast(data_, from_type, to_type); META_HPP_ASSERT(to_ptr); diff --git a/headers/meta.hpp/meta_detail/value_utilities/uinst.hpp b/headers/meta.hpp/meta_detail/value_utilities/uinst.hpp index 787b094..3012238 100644 --- a/headers/meta.hpp/meta_detail/value_utilities/uinst.hpp +++ b/headers/meta.hpp/meta_detail/value_utilities/uinst.hpp @@ -43,12 +43,12 @@ namespace meta_hpp::detail template < inst_class_lvalue_ref_kind T > explicit uinst_base(type_registry& registry, type_list) : ref_type_{std::is_const_v> ? ref_types::const_lvalue : ref_types::lvalue} - , raw_type_{registry.resolve_type>()} {} + , raw_type_{registry.resolve_by_type>()} {} template < inst_class_rvalue_ref_kind T > explicit uinst_base(type_registry& registry, type_list) : ref_type_{std::is_const_v> ? ref_types::const_rvalue : ref_types::rvalue} - , raw_type_{registry.resolve_type>()} {} + , raw_type_{registry.resolve_by_type>()} {} explicit uinst_base(type_registry&, uvalue& v) : ref_type_{ref_types::lvalue} @@ -155,7 +155,7 @@ namespace meta_hpp::detail using inst_method = typename inst_traits::method_type; const any_type& from_type = get_raw_type(); - const any_type& to_type = registry.resolve_type(); + const any_type& to_type = registry.resolve_by_type(); if ( from_type.is_class() ) { const auto is_invocable = [this]() { @@ -202,7 +202,7 @@ namespace meta_hpp::detail using inst_class = std::remove_cv_t; const any_type& from_type = get_raw_type(); - const any_type& to_type = registry.resolve_type(); + const any_type& to_type = registry.resolve_by_type(); if ( from_type.is_class() && to_type.is_class() ) { void* to_ptr = pointer_upcast( // diff --git a/headers/meta.hpp/meta_detail/value_utilities/utraits.hpp b/headers/meta.hpp/meta_detail/value_utilities/utraits.hpp index 5841732..921058b 100644 --- a/headers/meta.hpp/meta_detail/value_utilities/utraits.hpp +++ b/headers/meta.hpp/meta_detail/value_utilities/utraits.hpp @@ -184,8 +184,8 @@ namespace meta_hpp::detail [[nodiscard]] To* pointer_upcast(type_registry& registry, From* ptr) { return static_cast(pointer_upcast( // ptr, - registry.resolve_type(), - registry.resolve_type() + registry.resolve_by_type(), + registry.resolve_by_type() )); } @@ -193,8 +193,8 @@ namespace meta_hpp::detail [[nodiscard]] const To* pointer_upcast(type_registry& registry, const From* ptr) { return static_cast(pointer_upcast( // ptr, - registry.resolve_type(), - registry.resolve_type() + registry.resolve_by_type(), + registry.resolve_by_type() )); } } diff --git a/headers/meta.hpp/meta_details.hpp b/headers/meta.hpp/meta_details.hpp index 410189c..43c6041 100644 --- a/headers/meta.hpp/meta_details.hpp +++ b/headers/meta.hpp/meta_details.hpp @@ -9,7 +9,6 @@ #include "meta_base.hpp" #include "meta_detail/type_family.hpp" -#include "meta_detail/type_kinds.hpp" namespace meta_hpp { diff --git a/headers/meta.hpp/meta_registry.hpp b/headers/meta.hpp/meta_registry.hpp index 69f3bad..e8e2fbc 100644 --- a/headers/meta.hpp/meta_registry.hpp +++ b/headers/meta.hpp/meta_registry.hpp @@ -33,7 +33,7 @@ namespace meta_hpp [[nodiscard]] auto resolve_type() { using namespace detail; type_registry& registry = type_registry::instance(); - return registry.resolve_type>(); + return registry.resolve_by_type>(); } template < typename T > @@ -53,7 +53,7 @@ namespace meta_hpp return detail::get_meta_poly_info(registry, from).type; } else { (void)from; - return registry.resolve_type(); + return registry.resolve_by_type(); } } } diff --git a/headers/meta.hpp/meta_states/argument.hpp b/headers/meta.hpp/meta_states/argument.hpp index 98d6e1a..87b212b 100644 --- a/headers/meta.hpp/meta_states/argument.hpp +++ b/headers/meta.hpp/meta_states/argument.hpp @@ -22,7 +22,7 @@ namespace meta_hpp::detail type_registry& registry{type_registry::instance()}; argument_state state{ - argument_index{registry.resolve_type(), position}, + argument_index{registry.resolve_by_type(), position}, std::move(metadata), }; diff --git a/headers/meta.hpp/meta_states/constructor.hpp b/headers/meta.hpp/meta_states/constructor.hpp index 22eb567..e7a61aa 100644 --- a/headers/meta.hpp/meta_states/constructor.hpp +++ b/headers/meta.hpp/meta_states/constructor.hpp @@ -151,7 +151,7 @@ namespace meta_hpp::detail type_registry& registry{type_registry::instance()}; constructor_state state{ - constructor_index{registry.resolve_constructor_type()}, + constructor_index{registry.resolve_by_traits>()}, std::move(metadata), }; diff --git a/headers/meta.hpp/meta_states/destructor.hpp b/headers/meta.hpp/meta_states/destructor.hpp index e55404e..9b140cf 100644 --- a/headers/meta.hpp/meta_states/destructor.hpp +++ b/headers/meta.hpp/meta_states/destructor.hpp @@ -82,7 +82,7 @@ namespace meta_hpp::detail type_registry& registry{type_registry::instance()}; destructor_state state{ - destructor_index{registry.resolve_destructor_type()}, + destructor_index{registry.resolve_by_traits>()}, std::move(metadata), }; diff --git a/headers/meta.hpp/meta_states/evalue.hpp b/headers/meta.hpp/meta_states/evalue.hpp index 72b3377..7f762a8 100644 --- a/headers/meta.hpp/meta_states/evalue.hpp +++ b/headers/meta.hpp/meta_states/evalue.hpp @@ -23,7 +23,7 @@ namespace meta_hpp::detail type_registry& registry{type_registry::instance()}; evalue_state state{ - evalue_index{registry.resolve_type(), std::move(name)}, + evalue_index{registry.resolve_by_type(), std::move(name)}, std::move(metadata), }; diff --git a/headers/meta.hpp/meta_states/function.hpp b/headers/meta.hpp/meta_states/function.hpp index 5af6edb..32801eb 100644 --- a/headers/meta.hpp/meta_states/function.hpp +++ b/headers/meta.hpp/meta_states/function.hpp @@ -122,7 +122,7 @@ namespace meta_hpp::detail type_registry& registry{type_registry::instance()}; function_state state{ - function_index{registry.resolve_type>(), std::move(name)}, + function_index{registry.resolve_by_type>(), std::move(name)}, std::move(metadata), }; diff --git a/headers/meta.hpp/meta_states/member.hpp b/headers/meta.hpp/meta_states/member.hpp index 40a9c49..80b2cd6 100644 --- a/headers/meta.hpp/meta_states/member.hpp +++ b/headers/meta.hpp/meta_states/member.hpp @@ -199,7 +199,7 @@ namespace meta_hpp::detail type_registry& registry{type_registry::instance()}; member_state state{ - member_index{registry.resolve_type(), std::move(name)}, + member_index{registry.resolve_by_type(), std::move(name)}, std::move(metadata), }; diff --git a/headers/meta.hpp/meta_states/method.hpp b/headers/meta.hpp/meta_states/method.hpp index fb02451..6f44aff 100644 --- a/headers/meta.hpp/meta_states/method.hpp +++ b/headers/meta.hpp/meta_states/method.hpp @@ -134,7 +134,7 @@ namespace meta_hpp::detail type_registry& registry{type_registry::instance()}; method_state state{ - method_index{registry.resolve_type(), std::move(name)}, + method_index{registry.resolve_by_type(), std::move(name)}, std::move(metadata), }; diff --git a/headers/meta.hpp/meta_states/scope.hpp b/headers/meta.hpp/meta_states/scope.hpp index 6944966..948a67d 100644 --- a/headers/meta.hpp/meta_states/scope.hpp +++ b/headers/meta.hpp/meta_states/scope.hpp @@ -79,7 +79,7 @@ namespace meta_hpp std::string_view name ) const noexcept { detail::type_registry& registry{detail::type_registry::instance()}; - return get_function_with(name, {registry.resolve_type()...}); + return get_function_with(name, {registry.resolve_by_type()...}); } template < typename Iter > diff --git a/headers/meta.hpp/meta_states/variable.hpp b/headers/meta.hpp/meta_states/variable.hpp index 5161475..215e546 100644 --- a/headers/meta.hpp/meta_states/variable.hpp +++ b/headers/meta.hpp/meta_states/variable.hpp @@ -120,7 +120,7 @@ namespace meta_hpp::detail type_registry& registry{type_registry::instance()}; variable_state state{ - variable_index{registry.resolve_type(), std::move(name)}, + variable_index{registry.resolve_by_type(), std::move(name)}, std::move(metadata), }; diff --git a/headers/meta.hpp/meta_types.hpp b/headers/meta.hpp/meta_types.hpp index 92ff98a..f837568 100644 --- a/headers/meta.hpp/meta_types.hpp +++ b/headers/meta.hpp/meta_types.hpp @@ -11,7 +11,6 @@ #include "meta_uvalue.hpp" #include "meta_detail/type_family.hpp" -#include "meta_detail/type_kinds.hpp" namespace meta_hpp { @@ -438,7 +437,7 @@ namespace meta_hpp::detail // NOLINTEND(*-avoid-const-or-ref-data-members) template < array_kind Array > - explicit array_type_data(type_list); + explicit array_type_data(array_traits); }; struct class_type_data final : type_data_base { @@ -473,7 +472,7 @@ namespace meta_hpp::detail deep_upcasts_t deep_upcasts; template < class_kind Class > - explicit class_type_data(type_list); + explicit class_type_data(class_traits); }; struct constructor_type_data final : type_data_base { @@ -484,7 +483,7 @@ namespace meta_hpp::detail // NOLINTEND(*-avoid-const-or-ref-data-members) template < class_kind Class, typename... Args > - explicit constructor_type_data(type_list, type_list); + explicit constructor_type_data(constructor_traits); }; struct destructor_type_data final : type_data_base { @@ -494,7 +493,7 @@ namespace meta_hpp::detail // NOLINTEND(*-avoid-const-or-ref-data-members) template < class_kind Class > - explicit destructor_type_data(type_list); + explicit destructor_type_data(destructor_traits); }; struct enum_type_data final : type_data_base { @@ -506,7 +505,7 @@ namespace meta_hpp::detail evalue_list evalues; template < enum_kind Enum > - explicit enum_type_data(type_list); + explicit enum_type_data(enum_traits); }; struct function_type_data final : type_data_base { @@ -517,7 +516,7 @@ namespace meta_hpp::detail // NOLINTEND(*-avoid-const-or-ref-data-members) template < function_kind Function > - explicit function_type_data(type_list); + explicit function_type_data(function_traits); }; struct member_type_data final : type_data_base { @@ -528,7 +527,7 @@ namespace meta_hpp::detail // NOLINTEND(*-avoid-const-or-ref-data-members) template < member_pointer_kind Member > - explicit member_type_data(type_list); + explicit member_type_data(member_traits); }; struct method_type_data final : type_data_base { @@ -540,12 +539,12 @@ namespace meta_hpp::detail // NOLINTEND(*-avoid-const-or-ref-data-members) template < method_pointer_kind Method > - explicit method_type_data(type_list); + explicit method_type_data(method_traits); }; struct nullptr_type_data final : type_data_base { template < nullptr_kind Nullptr > - explicit nullptr_type_data(type_list); + explicit nullptr_type_data(nullptr_traits); }; struct number_type_data final : type_data_base { @@ -556,7 +555,7 @@ namespace meta_hpp::detail // NOLINTEND(*-avoid-const-or-ref-data-members) template < number_kind Number > - explicit number_type_data(type_list); + explicit number_type_data(number_traits); }; struct pointer_type_data final : type_data_base { @@ -566,7 +565,7 @@ namespace meta_hpp::detail // NOLINTEND(*-avoid-const-or-ref-data-members) template < pointer_kind Pointer > - explicit pointer_type_data(type_list); + explicit pointer_type_data(pointer_traits); }; struct reference_type_data final : type_data_base { @@ -576,12 +575,12 @@ namespace meta_hpp::detail // NOLINTEND(*-avoid-const-or-ref-data-members) template < reference_kind Reference > - explicit reference_type_data(type_list); + explicit reference_type_data(reference_traits); }; struct void_type_data final : type_data_base { template < void_kind Void > - explicit void_type_data(type_list); + explicit void_type_data(void_traits); }; } diff --git a/headers/meta.hpp/meta_types/array_type.hpp b/headers/meta.hpp/meta_types/array_type.hpp index 4ae873a..bc7589c 100644 --- a/headers/meta.hpp/meta_types/array_type.hpp +++ b/headers/meta.hpp/meta_types/array_type.hpp @@ -16,8 +16,8 @@ namespace meta_hpp::detail { template < array_kind Array > - array_type_data::array_type_data(type_list) - : type_data_base{type_kind::array_, shared_type_data_hash{}(this)} + array_type_data::array_type_data(array_traits) + : type_data_base{type_kind::array_, shared_traits_hash>{}(this)} , flags{array_traits::make_flags()} , extent{array_traits::extent} , data_type{resolve_type::data_type>()} {} diff --git a/headers/meta.hpp/meta_types/class_type.hpp b/headers/meta.hpp/meta_types/class_type.hpp index efa6d93..8a45790 100644 --- a/headers/meta.hpp/meta_types/class_type.hpp +++ b/headers/meta.hpp/meta_types/class_type.hpp @@ -105,8 +105,8 @@ namespace meta_hpp::detail::class_type_data_impl namespace meta_hpp::detail { template < class_kind Class > - class_type_data::class_type_data(type_list) - : type_data_base{type_kind::class_, shared_type_data_hash{}(this)} + class_type_data::class_type_data(class_traits) + : type_data_base{type_kind::class_, shared_traits_hash>{}(this)} , flags{class_traits::make_flags()} , size{class_traits::size} , align{class_traits::align} @@ -397,7 +397,7 @@ namespace meta_hpp template < typename... Args > constructor class_type::get_constructor_with() const noexcept { detail::type_registry& registry{detail::type_registry::instance()}; - return get_constructor_with({registry.resolve_type()...}); + return get_constructor_with({registry.resolve_by_type()...}); } template < typename Iter > @@ -442,7 +442,7 @@ namespace meta_hpp bool recursively ) const noexcept { detail::type_registry& registry{detail::type_registry::instance()}; - return get_function_with(name, {registry.resolve_type()...}, recursively); + return get_function_with(name, {registry.resolve_by_type()...}, recursively); } template < typename Iter > @@ -502,7 +502,7 @@ namespace meta_hpp bool recursively ) const noexcept { detail::type_registry& registry{detail::type_registry::instance()}; - return get_method_with(name, {registry.resolve_type()...}, recursively); + return get_method_with(name, {registry.resolve_by_type()...}, recursively); } template < typename Iter > diff --git a/headers/meta.hpp/meta_types/constructor_type.hpp b/headers/meta.hpp/meta_types/constructor_type.hpp index bb66442..2db2850 100644 --- a/headers/meta.hpp/meta_types/constructor_type.hpp +++ b/headers/meta.hpp/meta_types/constructor_type.hpp @@ -37,8 +37,8 @@ namespace meta_hpp::detail::constructor_type_data_impl namespace meta_hpp::detail { template < class_kind Class, typename... Args > - constructor_type_data::constructor_type_data(type_list, type_list) - : type_data_base{type_kind::constructor_, shared_type_data_hash{}(this)} + constructor_type_data::constructor_type_data(constructor_traits) + : type_data_base{type_kind::constructor_, shared_traits_hash>{}(this)} , flags{constructor_traits::make_flags()} , owner_type{resolve_type::class_type>()} , argument_types(constructor_type_data_impl::make_argument_types()) {} diff --git a/headers/meta.hpp/meta_types/destructor_type.hpp b/headers/meta.hpp/meta_types/destructor_type.hpp index 3212c91..302e309 100644 --- a/headers/meta.hpp/meta_types/destructor_type.hpp +++ b/headers/meta.hpp/meta_types/destructor_type.hpp @@ -16,8 +16,8 @@ namespace meta_hpp::detail { template < class_kind Class > - destructor_type_data::destructor_type_data(type_list) - : type_data_base{type_kind::destructor_, shared_type_data_hash{}(this)} + destructor_type_data::destructor_type_data(destructor_traits) + : type_data_base{type_kind::destructor_, shared_traits_hash>{}(this)} , flags{destructor_traits::make_flags()} , owner_type{resolve_type::class_type>()} {} } diff --git a/headers/meta.hpp/meta_types/enum_type.hpp b/headers/meta.hpp/meta_types/enum_type.hpp index a6dfc6c..f32fc35 100644 --- a/headers/meta.hpp/meta_types/enum_type.hpp +++ b/headers/meta.hpp/meta_types/enum_type.hpp @@ -19,8 +19,8 @@ namespace meta_hpp::detail { template < enum_kind Enum > - enum_type_data::enum_type_data(type_list) - : type_data_base{type_kind::enum_, shared_type_data_hash{}(this)} + enum_type_data::enum_type_data(enum_traits) + : type_data_base{type_kind::enum_, shared_traits_hash>{}(this)} , flags{enum_traits::make_flags()} , underlying_type{resolve_type::underlying_type>()} {} } diff --git a/headers/meta.hpp/meta_types/function_type.hpp b/headers/meta.hpp/meta_types/function_type.hpp index ba3032c..7ca2387 100644 --- a/headers/meta.hpp/meta_types/function_type.hpp +++ b/headers/meta.hpp/meta_types/function_type.hpp @@ -37,8 +37,8 @@ namespace meta_hpp::detail::function_type_data_impl namespace meta_hpp::detail { template < function_kind Function > - function_type_data::function_type_data(type_list) - : type_data_base{type_kind::function_, shared_type_data_hash{}(this)} + function_type_data::function_type_data(function_traits) + : type_data_base{type_kind::function_, shared_traits_hash>{}(this)} , flags{function_traits::make_flags()} , return_type{resolve_type::return_type>()} , argument_types(function_type_data_impl::make_argument_types()) {} diff --git a/headers/meta.hpp/meta_types/member_type.hpp b/headers/meta.hpp/meta_types/member_type.hpp index c133aa1..0202a93 100644 --- a/headers/meta.hpp/meta_types/member_type.hpp +++ b/headers/meta.hpp/meta_types/member_type.hpp @@ -16,8 +16,8 @@ namespace meta_hpp::detail { template < member_pointer_kind Member > - member_type_data::member_type_data(type_list) - : type_data_base{type_kind::member_, shared_type_data_hash{}(this)} + member_type_data::member_type_data(member_traits) + : type_data_base{type_kind::member_, shared_traits_hash>{}(this)} , flags{member_traits::make_flags()} , owner_type{resolve_type::class_type>()} , value_type{resolve_type::value_type>()} {} diff --git a/headers/meta.hpp/meta_types/method_type.hpp b/headers/meta.hpp/meta_types/method_type.hpp index 5a8d2aa..1d683d5 100644 --- a/headers/meta.hpp/meta_types/method_type.hpp +++ b/headers/meta.hpp/meta_types/method_type.hpp @@ -37,8 +37,8 @@ namespace meta_hpp::detail::method_type_data_impl namespace meta_hpp::detail { template < method_pointer_kind Method > - method_type_data::method_type_data(type_list) - : type_data_base{type_kind::method_, shared_type_data_hash{}(this)} + method_type_data::method_type_data(method_traits) + : type_data_base{type_kind::method_, shared_traits_hash>{}(this)} , flags{method_traits::make_flags()} , owner_type{resolve_type::class_type>()} , return_type{resolve_type::return_type>()} diff --git a/headers/meta.hpp/meta_types/nullptr_type.hpp b/headers/meta.hpp/meta_types/nullptr_type.hpp index 74c7164..2e6486e 100644 --- a/headers/meta.hpp/meta_types/nullptr_type.hpp +++ b/headers/meta.hpp/meta_types/nullptr_type.hpp @@ -15,6 +15,6 @@ namespace meta_hpp::detail { template < nullptr_kind Nullptr > - nullptr_type_data::nullptr_type_data(type_list) - : type_data_base{type_kind::nullptr_, shared_type_data_hash{}(this)} {} + nullptr_type_data::nullptr_type_data(nullptr_traits) + : type_data_base{type_kind::nullptr_, shared_traits_hash>{}(this)} {} } diff --git a/headers/meta.hpp/meta_types/number_type.hpp b/headers/meta.hpp/meta_types/number_type.hpp index 5eb58b3..3fede9f 100644 --- a/headers/meta.hpp/meta_types/number_type.hpp +++ b/headers/meta.hpp/meta_types/number_type.hpp @@ -16,8 +16,8 @@ namespace meta_hpp::detail { template < number_kind Number > - number_type_data::number_type_data(type_list) - : type_data_base{type_kind::number_, shared_type_data_hash{}(this)} + number_type_data::number_type_data(number_traits) + : type_data_base{type_kind::number_, shared_traits_hash>{}(this)} , flags{number_traits::make_flags()} , size{number_traits::size} , align{number_traits::align} {} diff --git a/headers/meta.hpp/meta_types/pointer_type.hpp b/headers/meta.hpp/meta_types/pointer_type.hpp index 30a5b78..9ede215 100644 --- a/headers/meta.hpp/meta_types/pointer_type.hpp +++ b/headers/meta.hpp/meta_types/pointer_type.hpp @@ -16,8 +16,8 @@ namespace meta_hpp::detail { template < pointer_kind Pointer > - pointer_type_data::pointer_type_data(type_list) - : type_data_base{type_kind::pointer_, shared_type_data_hash{}(this)} + pointer_type_data::pointer_type_data(pointer_traits) + : type_data_base{type_kind::pointer_, shared_traits_hash>{}(this)} , flags{pointer_traits::make_flags()} , data_type{resolve_type::data_type>()} {} } diff --git a/headers/meta.hpp/meta_types/reference_type.hpp b/headers/meta.hpp/meta_types/reference_type.hpp index 49ea01b..68b586d 100644 --- a/headers/meta.hpp/meta_types/reference_type.hpp +++ b/headers/meta.hpp/meta_types/reference_type.hpp @@ -16,8 +16,8 @@ namespace meta_hpp::detail { template < reference_kind Reference > - reference_type_data::reference_type_data(type_list) - : type_data_base{type_kind::reference_, shared_type_data_hash{}(this)} + reference_type_data::reference_type_data(reference_traits) + : type_data_base{type_kind::reference_, shared_traits_hash>{}(this)} , flags{reference_traits::make_flags()} , data_type{resolve_type::data_type>()} {} } diff --git a/headers/meta.hpp/meta_types/void_type.hpp b/headers/meta.hpp/meta_types/void_type.hpp index cb53989..be7f29a 100644 --- a/headers/meta.hpp/meta_types/void_type.hpp +++ b/headers/meta.hpp/meta_types/void_type.hpp @@ -15,6 +15,6 @@ namespace meta_hpp::detail { template < void_kind Void > - void_type_data::void_type_data(type_list) - : type_data_base{type_kind::void_, shared_type_data_hash{}(this)} {} + void_type_data::void_type_data(void_traits) + : type_data_base{type_kind::void_, shared_traits_hash>{}(this)} {} } diff --git a/headers/meta.hpp/meta_ucast/ucast.hpp b/headers/meta.hpp/meta_ucast/ucast.hpp index 7bb06f1..062e32a 100644 --- a/headers/meta.hpp/meta_ucast/ucast.hpp +++ b/headers/meta.hpp/meta_ucast/ucast.hpp @@ -46,7 +46,7 @@ namespace meta_hpp if constexpr ( std::is_void_v ) { return most_derived_object_ptr; } else { - const class_type& to_class_type = registry.resolve_class_type(); + const class_type& to_class_type = registry.resolve_by_type(); return static_cast(detail::pointer_upcast(most_derived_object_ptr, meta_info.type, to_class_type)); } }