From 2866b71e87fd03ae451500cc2d9dc828750a393e Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Sat, 11 Mar 2023 22:32:26 +0700 Subject: [PATCH] type_id is just a data pointer now --- develop/singles/headers/meta.hpp/meta_all.hpp | 269 ++++++------------ develop/untests/meta_base/type_id_base.cpp | 57 ---- .../untests/meta_issues/random_issue_3.cpp | 26 -- headers/meta.hpp/meta_base.hpp | 2 - headers/meta.hpp/meta_base/intrusive_ptr.hpp | 3 +- headers/meta.hpp/meta_base/type_id.hpp | 74 ----- .../meta.hpp/meta_detail/type_registry.hpp | 10 - headers/meta.hpp/meta_states.hpp | 8 +- headers/meta.hpp/meta_types.hpp | 41 ++- headers/meta.hpp/meta_types/array_type.hpp | 5 +- headers/meta.hpp/meta_types/class_type.hpp | 5 +- .../meta.hpp/meta_types/constructor_type.hpp | 5 +- .../meta.hpp/meta_types/destructor_type.hpp | 5 +- headers/meta.hpp/meta_types/enum_type.hpp | 5 +- headers/meta.hpp/meta_types/function_type.hpp | 5 +- headers/meta.hpp/meta_types/member_type.hpp | 5 +- headers/meta.hpp/meta_types/method_type.hpp | 5 +- headers/meta.hpp/meta_types/nullptr_type.hpp | 5 +- headers/meta.hpp/meta_types/number_type.hpp | 5 +- headers/meta.hpp/meta_types/pointer_type.hpp | 5 +- .../meta.hpp/meta_types/reference_type.hpp | 5 +- headers/meta.hpp/meta_types/void_type.hpp | 5 +- headers/meta.hpp/meta_uresult/uresult.hpp | 2 +- 23 files changed, 143 insertions(+), 414 deletions(-) delete mode 100644 develop/untests/meta_base/type_id_base.cpp delete mode 100644 develop/untests/meta_issues/random_issue_3.cpp delete mode 100644 headers/meta.hpp/meta_base/type_id.hpp diff --git a/develop/singles/headers/meta.hpp/meta_all.hpp b/develop/singles/headers/meta.hpp/meta_all.hpp index 89a5daa..d505abf 100644 --- a/develop/singles/headers/meta.hpp/meta_all.hpp +++ b/develop/singles/headers/meta.hpp/meta_all.hpp @@ -1190,7 +1190,7 @@ namespace meta_hpp::detail } [[nodiscard]] std::size_t get_hash() const noexcept { - return std::hash{}(ptr_); + return hash_combiner{}(ptr_); } [[nodiscard]] bool operator==(const intrusive_ptr& other) const noexcept { @@ -1514,108 +1514,6 @@ namespace meta_hpp::detail } } -namespace meta_hpp::detail -{ - template < typename... Types > - struct type_list {}; - - template < std::size_t I > - using size_constant = std::integral_constant; - - template < std::size_t I > - using index_constant = std::integral_constant; -} - -namespace meta_hpp::detail -{ - template < std::size_t Index, typename TypeList > - struct type_list_at; - - template < std::size_t Index, typename... Types > - struct type_list_at> { - using type = std::tuple_element_t>; - }; - - template < std::size_t Index, typename TypeList > - using type_list_at_t = typename type_list_at::type; -} - -namespace meta_hpp::detail -{ - template < typename TypeList > - struct type_list_arity; - - template < typename... Types > - struct type_list_arity> : size_constant {}; - - template < typename TypeList > - inline constexpr std::size_t type_list_arity_v = type_list_arity::value; -} - -namespace meta_hpp::detail -{ - class type_id final { - public: - template < typename T > - explicit type_id(type_list) noexcept - : id_{type_to_id()} {} - - type_id(type_id&&) = default; - type_id(const type_id&) = default; - - type_id& operator=(type_id&&) = default; - type_id& operator=(const type_id&) = default; - - ~type_id() = default; - - void swap(type_id& other) noexcept { - std::swap(id_, other.id_); - } - - [[nodiscard]] std::size_t get_hash() const noexcept { - return std::hash{}(id_); - } - - [[nodiscard]] bool operator==(type_id other) const noexcept { - return id_ == other.id_; - } - - [[nodiscard]] std::strong_ordering operator<=>(type_id other) const noexcept { - return id_ <=> other.id_; - } - - private: - using underlying_type = std::uint32_t; - underlying_type id_{}; - - private: - [[nodiscard]] static underlying_type next() noexcept { - static std::atomic id{}; - return ++id; - } - - template < typename T > - [[nodiscard]] static underlying_type type_to_id() noexcept { - static const underlying_type id{next()}; - return id; - } - }; - - inline void swap(type_id& l, type_id& r) noexcept { - l.swap(r); - } -} - -namespace std -{ - template <> - struct hash { - size_t operator()(const meta_hpp::detail::type_id& id) const noexcept { - return id.get_hash(); - } - }; -} - namespace meta_hpp::detail { template < typename T > @@ -1694,6 +1592,44 @@ namespace meta_hpp::detail } } +namespace meta_hpp::detail +{ + template < typename... Types > + struct type_list {}; + + template < std::size_t I > + using size_constant = std::integral_constant; + + template < std::size_t I > + using index_constant = std::integral_constant; +} + +namespace meta_hpp::detail +{ + template < std::size_t Index, typename TypeList > + struct type_list_at; + + template < std::size_t Index, typename... Types > + struct type_list_at> { + using type = std::tuple_element_t>; + }; + + template < std::size_t Index, typename TypeList > + using type_list_at_t = typename type_list_at::type; +} + +namespace meta_hpp::detail +{ + template < typename TypeList > + struct type_list_arity; + + template < typename... Types > + struct type_list_arity> : size_constant {}; + + template < typename TypeList > + inline constexpr std::size_t type_list_arity_v = type_list_arity::value; +} + namespace meta_hpp { using detail::error_code; @@ -1707,7 +1643,6 @@ namespace meta_hpp using detail::select_non_const; using detail::select_overload; - using detail::type_id; using detail::type_kind; using detail::type_list; } @@ -2541,6 +2476,30 @@ namespace meta_hpp using detail::reference_flags; } +namespace meta_hpp +{ + class type_id final { + public: + type_id() = default; + + explicit type_id(std::uintptr_t id) + : id_{id} {} + + void swap(type_id& other) noexcept { + std::swap(id_, other.id_); + } + + [[nodiscard]] std::size_t get_hash() const noexcept { + return detail::hash_combiner{}(id_); + } + + [[nodiscard]] std::strong_ordering operator<=>(const type_id& other) const = default; + + private: + std::uintptr_t id_{}; + }; +} + namespace meta_hpp { template < detail::type_family Type > @@ -2549,6 +2508,8 @@ namespace meta_hpp friend data_ptr detail::type_access(const Type&); public: + using id_type = type_id; + type_base() = default; explicit type_base(data_ptr data) @@ -2568,8 +2529,9 @@ namespace meta_hpp return is_valid(); } - [[nodiscard]] type_id get_id() const noexcept { - return data_->id; + [[nodiscard]] id_type get_id() const noexcept { + // NOLINTNEXTLINE(*-reinterpret-cast) + return id_type{reinterpret_cast(data_)}; } [[nodiscard]] type_kind get_kind() const noexcept { @@ -2895,12 +2857,12 @@ namespace meta_hpp namespace meta_hpp { template < detail::type_family L > - [[nodiscard]] bool operator==(const L& l, type_id r) noexcept { + [[nodiscard]] bool operator==(const L& l, const typename L::id_type& r) noexcept { return l.is_valid() && l.get_id() == r; } template < detail::type_family L > - [[nodiscard]] std::strong_ordering operator<=>(const L& l, type_id r) noexcept { + [[nodiscard]] std::strong_ordering operator<=>(const L& l, const typename L::id_type& r) noexcept { return l.is_valid() ? l.get_id() <=> r : std::strong_ordering::less; } } @@ -2908,14 +2870,12 @@ namespace meta_hpp namespace meta_hpp::detail { struct type_data_base { - const type_id id; const type_kind kind; metadata_map metadata{}; - explicit type_data_base(type_id nid, type_kind nkind) - : id{nid} - , kind{nkind} {} + explicit type_data_base(type_kind nkind) + : kind{nkind} {} type_data_base(type_data_base&&) = delete; type_data_base(const type_data_base&) = delete; @@ -4024,13 +3984,13 @@ namespace meta_hpp namespace meta_hpp { - template < detail::state_family L, detail::index_family R > - [[nodiscard]] bool operator==(const L& l, const R& r) noexcept { + template < detail::state_family L > + [[nodiscard]] bool operator==(const L& l, const typename L::index_type& r) noexcept { return l.is_valid() && l.get_index() == r; } - template < detail::state_family L, detail::index_family R > - [[nodiscard]] std::strong_ordering operator<=>(const L& l, const R& r) noexcept { + template < detail::state_family L > + [[nodiscard]] std::strong_ordering operator<=>(const L& l, const typename L::index_type& r) noexcept { return l.is_valid() ? l.get_index() <=> r : std::strong_ordering::less; } } @@ -4213,16 +4173,6 @@ namespace meta_hpp::detail } } - [[nodiscard]] any_type get_type_by_id(type_id id) const noexcept { - const locker lock; - - if ( auto iter{types_.find(id)}; iter != types_.end() ) { - return *iter; - } - - return any_type{}; - } - public: template < typename T > [[nodiscard]] auto resolve_type() { @@ -6281,12 +6231,9 @@ namespace meta_hpp::detail namespace meta_hpp::detail { - template < function_pointer_kind Function > - struct function_tag {}; - template < function_pointer_kind Function > function_type_data::function_type_data(type_list) - : type_data_base{type_id{type_list>{}}, type_kind::function_} + : type_data_base{type_kind::function_} , flags{function_traits::make_flags()} , return_type{resolve_type::return_type>()} , argument_types{resolve_types(typename function_traits::argument_types{})} {} @@ -6722,12 +6669,9 @@ namespace meta_hpp::detail namespace meta_hpp::detail { - template < member_pointer_kind Member > - struct member_tag {}; - template < member_pointer_kind Member > member_type_data::member_type_data(type_list) - : type_data_base{type_id{type_list>{}}, type_kind::member_} + : type_data_base{type_kind::member_} , flags{member_traits::make_flags()} , owner_type{resolve_type::class_type>()} , value_type{resolve_type::value_type>()} {} @@ -7049,12 +6993,9 @@ namespace meta_hpp namespace meta_hpp::detail { - template < method_pointer_kind Method > - struct method_tag {}; - template < method_pointer_kind Method > method_type_data::method_type_data(type_list) - : type_data_base{type_id{type_list>{}}, type_kind::method_} + : type_data_base{type_kind::method_} , flags{method_traits::make_flags()} , owner_type{resolve_type::class_type>()} , return_type{resolve_type::return_type>()} @@ -7518,12 +7459,9 @@ namespace meta_hpp namespace meta_hpp::detail { - template < class_kind Class, typename... Args > - struct constructor_tag {}; - template < class_kind Class, typename... Args > constructor_type_data::constructor_type_data(type_list, type_list) - : type_data_base{type_id{type_list>{}}, type_kind::constructor_} + : type_data_base{type_kind::constructor_} , flags{constructor_traits::make_flags()} , owner_type{resolve_type::class_type>()} , argument_types{resolve_types(typename constructor_traits::argument_types{})} {} @@ -7773,12 +7711,9 @@ namespace meta_hpp namespace meta_hpp::detail { - template < class_kind Class > - struct destructor_tag {}; - template < class_kind Class > destructor_type_data::destructor_type_data(type_list) - : type_data_base{type_id{type_list>{}}, type_kind::destructor_} + : type_data_base{type_kind::destructor_} , flags{destructor_traits::make_flags()} , owner_type{resolve_type::class_type>()} {} } @@ -7928,12 +7863,9 @@ namespace meta_hpp namespace meta_hpp::detail { - template < enum_kind Enum > - struct enum_tag {}; - template < enum_kind Enum > enum_type_data::enum_type_data(type_list) - : type_data_base{type_id{type_list>{}}, type_kind::enum_} + : type_data_base{type_kind::enum_} , flags{enum_traits::make_flags()} , underlying_type{resolve_type::underlying_type>()} {} } @@ -8022,12 +7954,9 @@ namespace meta_hpp namespace meta_hpp::detail { - template < pointer_kind Pointer > - struct pointer_tag {}; - template < pointer_kind Pointer > pointer_type_data::pointer_type_data(type_list) - : type_data_base{type_id{type_list>{}}, type_kind::pointer_} + : type_data_base{type_kind::pointer_} , flags{pointer_traits::make_flags()} , data_type{resolve_type::data_type>()} {} } @@ -8227,12 +8156,9 @@ namespace meta_hpp namespace meta_hpp::detail { - template < class_kind Class > - struct class_tag {}; - template < class_kind Class > class_type_data::class_type_data(type_list) - : type_data_base{type_id{type_list>{}}, type_kind::class_} + : type_data_base{type_kind::class_} , flags{class_traits::make_flags()} , size{class_traits::size} , align{class_traits::align} @@ -8943,12 +8869,9 @@ namespace meta_hpp namespace meta_hpp::detail { - template < array_kind Array > - struct array_tag {}; - template < array_kind Array > array_type_data::array_type_data(type_list) - : type_data_base{type_id{type_list>{}}, type_kind::array_} + : type_data_base{type_kind::array_} , flags{array_traits::make_flags()} , extent{array_traits::extent} , data_type{resolve_type::data_type>()} {} @@ -8971,22 +8894,16 @@ namespace meta_hpp namespace meta_hpp::detail { - template < nullptr_kind Nullptr > - struct nullptr_tag {}; - template < nullptr_kind Nullptr > nullptr_type_data::nullptr_type_data(type_list) - : type_data_base{type_id{type_list>{}}, type_kind::nullptr_} {} + : type_data_base{type_kind::nullptr_} {} } namespace meta_hpp::detail { - template < number_kind Number > - struct number_tag {}; - template < number_kind Number > number_type_data::number_type_data(type_list) - : type_data_base{type_id{type_list>{}}, type_kind::number_} + : type_data_base{type_kind::number_} , flags{number_traits::make_flags()} , size{number_traits::size} , align{number_traits::align} {} @@ -9009,12 +8926,9 @@ namespace meta_hpp namespace meta_hpp::detail { - template < reference_kind Reference > - struct reference_tag {}; - template < reference_kind Reference > reference_type_data::reference_type_data(type_list) - : type_data_base{type_id{type_list>{}}, type_kind::reference_} + : type_data_base{type_kind::reference_} , flags{reference_traits::make_flags()} , data_type{resolve_type::data_type>()} {} } @@ -9032,12 +8946,9 @@ namespace meta_hpp namespace meta_hpp::detail { - template < void_kind Void > - struct void_tag {}; - template < void_kind Void > void_type_data::void_type_data(type_list) - : type_data_base{type_id{type_list>{}}, type_kind::void_} {} + : type_data_base{type_kind::void_} {} } namespace meta_hpp::detail @@ -9867,7 +9778,7 @@ namespace meta_hpp } inline std::size_t uerror::get_hash() const noexcept { - return std::hash{}(error_); + return detail::hash_combiner{}(error_); } } diff --git a/develop/untests/meta_base/type_id_base.cpp b/develop/untests/meta_base/type_id_base.cpp deleted file mode 100644 index 4239343..0000000 --- a/develop/untests/meta_base/type_id_base.cpp +++ /dev/null @@ -1,57 +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 - -TEST_CASE("meta/meta_base/type_id") { - namespace meta = meta_hpp; - using meta::detail::type_id; - using meta::detail::type_list; - - static_assert(std::is_nothrow_constructible_v>); - static_assert(std::is_nothrow_copy_constructible_v); - static_assert(std::is_nothrow_move_constructible_v); - static_assert(std::is_nothrow_copy_assignable_v); - static_assert(std::is_nothrow_move_assignable_v); - - SUBCASE("ctor") { - type_id int1_id{type_list{}}; - type_id int2_id{type_list{}}; - type_id float_id{type_list{}}; - - CHECK(int1_id == int2_id); - CHECK_FALSE(int2_id == float_id); - - CHECK((int2_id < float_id || float_id < int2_id)); - CHECK_FALSE((int1_id < int2_id || int2_id < int1_id)); - } - - SUBCASE("get_hash") { - type_id int1_id{type_list{}}; - type_id int2_id{type_list{}}; - type_id float_id{type_list{}}; - - CHECK(int1_id.get_hash() == int2_id.get_hash()); - CHECK_FALSE(int2_id.get_hash() == float_id.get_hash()); - } - - SUBCASE("swap") { - const type_id int_id{type_list{}}; - const type_id float_id{type_list{}}; - - type_id id1{type_list{}}; - type_id id2{type_list{}}; - - id1.swap(id2); - CHECK(id1 == float_id); - CHECK(id2 == int_id); - - swap(id1, id2); - CHECK(id1 == int_id); - CHECK(id2 == float_id); - } -} diff --git a/develop/untests/meta_issues/random_issue_3.cpp b/develop/untests/meta_issues/random_issue_3.cpp deleted file mode 100644 index 6c0e18c..0000000 --- a/develop/untests/meta_issues/random_issue_3.cpp +++ /dev/null @@ -1,26 +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 -{ - struct A {}; - struct B {}; -} - -TEST_CASE("meta/meta_issues/random/3") { - namespace meta = meta_hpp; - - meta::detail::type_registry& registry{meta::detail::type_registry::instance()}; - - meta::class_type a_type = registry.resolve_class_type(); - meta::class_type b_type = registry.resolve_class_type(); - - CHECK(registry.get_type_by_id(a_type.get_id()) == a_type); - CHECK(registry.get_type_by_id(b_type.get_id()) == b_type); -} diff --git a/headers/meta.hpp/meta_base.hpp b/headers/meta.hpp/meta_base.hpp index 150baae..009c6ef 100644 --- a/headers/meta.hpp/meta_base.hpp +++ b/headers/meta.hpp/meta_base.hpp @@ -27,7 +27,6 @@ #include "meta_base/overloaded.hpp" #include "meta_base/select_overload.hpp" #include "meta_base/to_underlying.hpp" -#include "meta_base/type_id.hpp" #include "meta_base/type_kinds.hpp" #include "meta_base/type_list.hpp" @@ -44,7 +43,6 @@ namespace meta_hpp using detail::select_non_const; using detail::select_overload; - using detail::type_id; using detail::type_kind; using detail::type_list; } diff --git a/headers/meta.hpp/meta_base/intrusive_ptr.hpp b/headers/meta.hpp/meta_base/intrusive_ptr.hpp index 1877dab..96db790 100644 --- a/headers/meta.hpp/meta_base/intrusive_ptr.hpp +++ b/headers/meta.hpp/meta_base/intrusive_ptr.hpp @@ -7,6 +7,7 @@ #pragma once #include "base.hpp" +#include "hash_combiner.hpp" namespace meta_hpp::detail { @@ -147,7 +148,7 @@ namespace meta_hpp::detail } [[nodiscard]] std::size_t get_hash() const noexcept { - return std::hash{}(ptr_); + return hash_combiner{}(ptr_); } [[nodiscard]] bool operator==(const intrusive_ptr& other) const noexcept { diff --git a/headers/meta.hpp/meta_base/type_id.hpp b/headers/meta.hpp/meta_base/type_id.hpp deleted file mode 100644 index a87e68e..0000000 --- a/headers/meta.hpp/meta_base/type_id.hpp +++ /dev/null @@ -1,74 +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 "type_list.hpp" - -namespace meta_hpp::detail -{ - class type_id final { - public: - template < typename T > - explicit type_id(type_list) noexcept - : id_{type_to_id()} {} - - type_id(type_id&&) = default; - type_id(const type_id&) = default; - - type_id& operator=(type_id&&) = default; - type_id& operator=(const type_id&) = default; - - ~type_id() = default; - - void swap(type_id& other) noexcept { - std::swap(id_, other.id_); - } - - [[nodiscard]] std::size_t get_hash() const noexcept { - return std::hash{}(id_); - } - - [[nodiscard]] bool operator==(type_id other) const noexcept { - return id_ == other.id_; - } - - [[nodiscard]] std::strong_ordering operator<=>(type_id other) const noexcept { - return id_ <=> other.id_; - } - - private: - using underlying_type = std::uint32_t; - underlying_type id_{}; - - private: - [[nodiscard]] static underlying_type next() noexcept { - static std::atomic id{}; - return ++id; - } - - template < typename T > - [[nodiscard]] static underlying_type type_to_id() noexcept { - static const underlying_type id{next()}; - return id; - } - }; - - inline void swap(type_id& l, type_id& r) noexcept { - l.swap(r); - } -} - -namespace std -{ - template <> - struct hash { - size_t operator()(const meta_hpp::detail::type_id& id) const noexcept { - return id.get_hash(); - } - }; -} diff --git a/headers/meta.hpp/meta_detail/type_registry.hpp b/headers/meta.hpp/meta_detail/type_registry.hpp index ca11295..bfee60f 100644 --- a/headers/meta.hpp/meta_detail/type_registry.hpp +++ b/headers/meta.hpp/meta_detail/type_registry.hpp @@ -45,16 +45,6 @@ namespace meta_hpp::detail } } - [[nodiscard]] any_type get_type_by_id(type_id id) const noexcept { - const locker lock; - - if ( auto iter{types_.find(id)}; iter != types_.end() ) { - return *iter; - } - - return any_type{}; - } - public: template < typename T > [[nodiscard]] auto resolve_type() { diff --git a/headers/meta.hpp/meta_states.hpp b/headers/meta.hpp/meta_states.hpp index 6c77243..f5f79a3 100644 --- a/headers/meta.hpp/meta_states.hpp +++ b/headers/meta.hpp/meta_states.hpp @@ -414,13 +414,13 @@ namespace meta_hpp namespace meta_hpp { - template < detail::state_family L, detail::index_family R > - [[nodiscard]] bool operator==(const L& l, const R& r) noexcept { + template < detail::state_family L > + [[nodiscard]] bool operator==(const L& l, const typename L::index_type& r) noexcept { return l.is_valid() && l.get_index() == r; } - template < detail::state_family L, detail::index_family R > - [[nodiscard]] std::strong_ordering operator<=>(const L& l, const R& r) noexcept { + template < detail::state_family L > + [[nodiscard]] std::strong_ordering operator<=>(const L& l, const typename L::index_type& r) noexcept { return l.is_valid() ? l.get_index() <=> r : std::strong_ordering::less; } } diff --git a/headers/meta.hpp/meta_types.hpp b/headers/meta.hpp/meta_types.hpp index fc289be..af7786a 100644 --- a/headers/meta.hpp/meta_types.hpp +++ b/headers/meta.hpp/meta_types.hpp @@ -46,6 +46,30 @@ namespace meta_hpp using detail::reference_flags; } +namespace meta_hpp +{ + class type_id final { + public: + type_id() = default; + + explicit type_id(std::uintptr_t id) + : id_{id} {} + + void swap(type_id& other) noexcept { + std::swap(id_, other.id_); + } + + [[nodiscard]] std::size_t get_hash() const noexcept { + return detail::hash_combiner{}(id_); + } + + [[nodiscard]] std::strong_ordering operator<=>(const type_id& other) const = default; + + private: + std::uintptr_t id_{}; + }; +} + namespace meta_hpp { template < detail::type_family Type > @@ -54,6 +78,8 @@ namespace meta_hpp friend data_ptr detail::type_access(const Type&); public: + using id_type = type_id; + type_base() = default; explicit type_base(data_ptr data) @@ -73,8 +99,9 @@ namespace meta_hpp return is_valid(); } - [[nodiscard]] type_id get_id() const noexcept { - return data_->id; + [[nodiscard]] id_type get_id() const noexcept { + // NOLINTNEXTLINE(*-reinterpret-cast) + return id_type{reinterpret_cast(data_)}; } [[nodiscard]] type_kind get_kind() const noexcept { @@ -400,12 +427,12 @@ namespace meta_hpp namespace meta_hpp { template < detail::type_family L > - [[nodiscard]] bool operator==(const L& l, type_id r) noexcept { + [[nodiscard]] bool operator==(const L& l, const typename L::id_type& r) noexcept { return l.is_valid() && l.get_id() == r; } template < detail::type_family L > - [[nodiscard]] std::strong_ordering operator<=>(const L& l, type_id r) noexcept { + [[nodiscard]] std::strong_ordering operator<=>(const L& l, const typename L::id_type& r) noexcept { return l.is_valid() ? l.get_id() <=> r : std::strong_ordering::less; } } @@ -413,14 +440,12 @@ namespace meta_hpp namespace meta_hpp::detail { struct type_data_base { - const type_id id; const type_kind kind; metadata_map metadata{}; - explicit type_data_base(type_id nid, type_kind nkind) - : id{nid} - , kind{nkind} {} + explicit type_data_base(type_kind nkind) + : kind{nkind} {} type_data_base(type_data_base&&) = delete; type_data_base(const type_data_base&) = delete; diff --git a/headers/meta.hpp/meta_types/array_type.hpp b/headers/meta.hpp/meta_types/array_type.hpp index d819bae..57cf8a7 100644 --- a/headers/meta.hpp/meta_types/array_type.hpp +++ b/headers/meta.hpp/meta_types/array_type.hpp @@ -14,12 +14,9 @@ namespace meta_hpp::detail { - template < array_kind Array > - struct array_tag {}; - template < array_kind Array > array_type_data::array_type_data(type_list) - : type_data_base{type_id{type_list>{}}, type_kind::array_} + : type_data_base{type_kind::array_} , 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 93c1cf2..8af5234 100644 --- a/headers/meta.hpp/meta_types/class_type.hpp +++ b/headers/meta.hpp/meta_types/class_type.hpp @@ -20,12 +20,9 @@ namespace meta_hpp::detail { - template < class_kind Class > - struct class_tag {}; - template < class_kind Class > class_type_data::class_type_data(type_list) - : type_data_base{type_id{type_list>{}}, type_kind::class_} + : type_data_base{type_kind::class_} , flags{class_traits::make_flags()} , size{class_traits::size} , align{class_traits::align} diff --git a/headers/meta.hpp/meta_types/constructor_type.hpp b/headers/meta.hpp/meta_types/constructor_type.hpp index 8e4c668..20fe71c 100644 --- a/headers/meta.hpp/meta_types/constructor_type.hpp +++ b/headers/meta.hpp/meta_types/constructor_type.hpp @@ -14,12 +14,9 @@ namespace meta_hpp::detail { - template < class_kind Class, typename... Args > - struct constructor_tag {}; - template < class_kind Class, typename... Args > constructor_type_data::constructor_type_data(type_list, type_list) - : type_data_base{type_id{type_list>{}}, type_kind::constructor_} + : type_data_base{type_kind::constructor_} , flags{constructor_traits::make_flags()} , owner_type{resolve_type::class_type>()} , argument_types{resolve_types(typename constructor_traits::argument_types{})} {} diff --git a/headers/meta.hpp/meta_types/destructor_type.hpp b/headers/meta.hpp/meta_types/destructor_type.hpp index 32188b4..bad227b 100644 --- a/headers/meta.hpp/meta_types/destructor_type.hpp +++ b/headers/meta.hpp/meta_types/destructor_type.hpp @@ -14,12 +14,9 @@ namespace meta_hpp::detail { - template < class_kind Class > - struct destructor_tag {}; - template < class_kind Class > destructor_type_data::destructor_type_data(type_list) - : type_data_base{type_id{type_list>{}}, type_kind::destructor_} + : type_data_base{type_kind::destructor_} , 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 4fe0d2e..a70af67 100644 --- a/headers/meta.hpp/meta_types/enum_type.hpp +++ b/headers/meta.hpp/meta_types/enum_type.hpp @@ -17,12 +17,9 @@ namespace meta_hpp::detail { - template < enum_kind Enum > - struct enum_tag {}; - template < enum_kind Enum > enum_type_data::enum_type_data(type_list) - : type_data_base{type_id{type_list>{}}, type_kind::enum_} + : type_data_base{type_kind::enum_} , 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 65a030e..ab928c5 100644 --- a/headers/meta.hpp/meta_types/function_type.hpp +++ b/headers/meta.hpp/meta_types/function_type.hpp @@ -14,12 +14,9 @@ namespace meta_hpp::detail { - template < function_pointer_kind Function > - struct function_tag {}; - template < function_pointer_kind Function > function_type_data::function_type_data(type_list) - : type_data_base{type_id{type_list>{}}, type_kind::function_} + : type_data_base{type_kind::function_} , flags{function_traits::make_flags()} , return_type{resolve_type::return_type>()} , argument_types{resolve_types(typename function_traits::argument_types{})} {} diff --git a/headers/meta.hpp/meta_types/member_type.hpp b/headers/meta.hpp/meta_types/member_type.hpp index a44d38f..0f1606d 100644 --- a/headers/meta.hpp/meta_types/member_type.hpp +++ b/headers/meta.hpp/meta_types/member_type.hpp @@ -14,12 +14,9 @@ namespace meta_hpp::detail { - template < member_pointer_kind Member > - struct member_tag {}; - template < member_pointer_kind Member > member_type_data::member_type_data(type_list) - : type_data_base{type_id{type_list>{}}, type_kind::member_} + : type_data_base{type_kind::member_} , 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 13c8a4a..c79715f 100644 --- a/headers/meta.hpp/meta_types/method_type.hpp +++ b/headers/meta.hpp/meta_types/method_type.hpp @@ -14,12 +14,9 @@ namespace meta_hpp::detail { - template < method_pointer_kind Method > - struct method_tag {}; - template < method_pointer_kind Method > method_type_data::method_type_data(type_list) - : type_data_base{type_id{type_list>{}}, type_kind::method_} + : type_data_base{type_kind::method_} , 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 c23eeeb..1751535 100644 --- a/headers/meta.hpp/meta_types/nullptr_type.hpp +++ b/headers/meta.hpp/meta_types/nullptr_type.hpp @@ -12,10 +12,7 @@ namespace meta_hpp::detail { - template < nullptr_kind Nullptr > - struct nullptr_tag {}; - template < nullptr_kind Nullptr > nullptr_type_data::nullptr_type_data(type_list) - : type_data_base{type_id{type_list>{}}, type_kind::nullptr_} {} + : type_data_base{type_kind::nullptr_} {} } diff --git a/headers/meta.hpp/meta_types/number_type.hpp b/headers/meta.hpp/meta_types/number_type.hpp index db7be5d..0094219 100644 --- a/headers/meta.hpp/meta_types/number_type.hpp +++ b/headers/meta.hpp/meta_types/number_type.hpp @@ -14,12 +14,9 @@ namespace meta_hpp::detail { - template < number_kind Number > - struct number_tag {}; - template < number_kind Number > number_type_data::number_type_data(type_list) - : type_data_base{type_id{type_list>{}}, type_kind::number_} + : type_data_base{type_kind::number_} , 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 2feeaf7..891f479 100644 --- a/headers/meta.hpp/meta_types/pointer_type.hpp +++ b/headers/meta.hpp/meta_types/pointer_type.hpp @@ -14,12 +14,9 @@ namespace meta_hpp::detail { - template < pointer_kind Pointer > - struct pointer_tag {}; - template < pointer_kind Pointer > pointer_type_data::pointer_type_data(type_list) - : type_data_base{type_id{type_list>{}}, type_kind::pointer_} + : type_data_base{type_kind::pointer_} , 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 d8da62b..a10e998 100644 --- a/headers/meta.hpp/meta_types/reference_type.hpp +++ b/headers/meta.hpp/meta_types/reference_type.hpp @@ -14,12 +14,9 @@ namespace meta_hpp::detail { - template < reference_kind Reference > - struct reference_tag {}; - template < reference_kind Reference > reference_type_data::reference_type_data(type_list) - : type_data_base{type_id{type_list>{}}, type_kind::reference_} + : type_data_base{type_kind::reference_} , 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 cd54952..9340433 100644 --- a/headers/meta.hpp/meta_types/void_type.hpp +++ b/headers/meta.hpp/meta_types/void_type.hpp @@ -12,10 +12,7 @@ namespace meta_hpp::detail { - template < void_kind Void > - struct void_tag {}; - template < void_kind Void > void_type_data::void_type_data(type_list) - : type_data_base{type_id{type_list>{}}, type_kind::void_} {} + : type_data_base{type_kind::void_} {} } diff --git a/headers/meta.hpp/meta_uresult/uresult.hpp b/headers/meta.hpp/meta_uresult/uresult.hpp index dcd803d..c836439 100644 --- a/headers/meta.hpp/meta_uresult/uresult.hpp +++ b/headers/meta.hpp/meta_uresult/uresult.hpp @@ -47,7 +47,7 @@ namespace meta_hpp } inline std::size_t uerror::get_hash() const noexcept { - return std::hash{}(error_); + return detail::hash_combiner{}(error_); } }