fix type duplication in the registry

This commit is contained in:
BlackMATov
2024-01-28 04:01:07 +07:00
parent 28e42523b4
commit 35f0f37efc
2 changed files with 38 additions and 58 deletions

View File

@@ -4163,92 +4163,79 @@ namespace meta_hpp::detail
template < array_kind Array > template < array_kind Array >
[[nodiscard]] array_type resolve_array_type() { [[nodiscard]] array_type resolve_array_type() {
using array_t = std::remove_cv_t<Array>; using array_t = std::remove_cv_t<Array>;
static array_type type{ensure_type<array_type_data>(type_list<array_t>{})}; return array_type{ensure_type<array_type_data>(type_list<array_t>{})};
return type;
} }
template < class_kind Class > template < class_kind Class >
[[nodiscard]] class_type resolve_class_type() { [[nodiscard]] class_type resolve_class_type() {
using class_t = std::remove_cv_t<Class>; using class_t = std::remove_cv_t<Class>;
static class_type type{ensure_type<class_type_data>(type_list<class_t>{})}; return class_type{ensure_type<class_type_data>(type_list<class_t>{})};
return type;
} }
template < class_kind Class, typename... Args > template < class_kind Class, typename... Args >
[[nodiscard]] constructor_type resolve_constructor_type() { [[nodiscard]] constructor_type resolve_constructor_type() {
using class_t = std::remove_cv_t<Class>; using class_t = std::remove_cv_t<Class>;
static constructor_type type{ensure_type<constructor_type_data>(type_list<class_t>{}, type_list<Args...>{})}; return constructor_type{ensure_type<constructor_type_data>(type_list<class_t>{}, type_list<Args...>{})};
return type;
} }
template < class_kind Class > template < class_kind Class >
[[nodiscard]] destructor_type resolve_destructor_type() { [[nodiscard]] destructor_type resolve_destructor_type() {
using class_t = std::remove_cv_t<Class>; using class_t = std::remove_cv_t<Class>;
static destructor_type type{ensure_type<destructor_type_data>(type_list<class_t>{})}; return destructor_type{ensure_type<destructor_type_data>(type_list<class_t>{})};
return type;
} }
template < enum_kind Enum > template < enum_kind Enum >
[[nodiscard]] enum_type resolve_enum_type() { [[nodiscard]] enum_type resolve_enum_type() {
using enum_t = std::remove_cv_t<Enum>; using enum_t = std::remove_cv_t<Enum>;
static enum_type type{ensure_type<enum_type_data>(type_list<enum_t>{})}; return enum_type{ensure_type<enum_type_data>(type_list<enum_t>{})};
return type;
} }
template < function_kind Function > template < function_kind Function >
[[nodiscard]] function_type resolve_function_type() { [[nodiscard]] function_type resolve_function_type() {
using function_t = std::remove_cv_t<Function>; using function_t = std::remove_cv_t<Function>;
static function_type type{ensure_type<function_type_data>(type_list<function_t>{})}; return function_type{ensure_type<function_type_data>(type_list<function_t>{})};
return type;
} }
template < member_pointer_kind Member > template < member_pointer_kind Member >
[[nodiscard]] member_type resolve_member_type() { [[nodiscard]] member_type resolve_member_type() {
using member_t = std::remove_cv_t<Member>; using member_t = std::remove_cv_t<Member>;
static member_type type{ensure_type<member_type_data>(type_list<member_t>{})}; return member_type{ensure_type<member_type_data>(type_list<member_t>{})};
return type;
} }
template < method_pointer_kind Method > template < method_pointer_kind Method >
[[nodiscard]] method_type resolve_method_type() { [[nodiscard]] method_type resolve_method_type() {
using method_t = std::remove_cv_t<Method>; using method_t = std::remove_cv_t<Method>;
static method_type type{ensure_type<method_type_data>(type_list<method_t>{})}; return method_type{ensure_type<method_type_data>(type_list<method_t>{})};
return type;
} }
template < nullptr_kind Nullptr > template < nullptr_kind Nullptr >
[[nodiscard]] nullptr_type resolve_nullptr_type() { [[nodiscard]] nullptr_type resolve_nullptr_type() {
using nullptr_t = std::remove_cv_t<Nullptr>; using nullptr_t = std::remove_cv_t<Nullptr>;
static nullptr_type type{ensure_type<nullptr_type_data>(type_list<nullptr_t>{})}; return nullptr_type{ensure_type<nullptr_type_data>(type_list<nullptr_t>{})};
return type;
} }
template < number_kind Number > template < number_kind Number >
[[nodiscard]] number_type resolve_number_type() { [[nodiscard]] number_type resolve_number_type() {
using number_t = std::remove_cv_t<Number>; using number_t = std::remove_cv_t<Number>;
static number_type type{ensure_type<number_type_data>(type_list<number_t>{})}; return number_type{ensure_type<number_type_data>(type_list<number_t>{})};
return type;
} }
template < pointer_kind Pointer > template < pointer_kind Pointer >
[[nodiscard]] pointer_type resolve_pointer_type() { [[nodiscard]] pointer_type resolve_pointer_type() {
using pointer_t = std::remove_cv_t<Pointer>; using pointer_t = std::remove_cv_t<Pointer>;
static pointer_type type{ensure_type<pointer_type_data>(type_list<pointer_t>{})}; return pointer_type{ensure_type<pointer_type_data>(type_list<pointer_t>{})};
return type;
} }
template < reference_kind Reference > template < reference_kind Reference >
[[nodiscard]] reference_type resolve_reference_type() { [[nodiscard]] reference_type resolve_reference_type() {
using reference_t = std::remove_cv_t<Reference>; using reference_t = std::remove_cv_t<Reference>;
static reference_type type{ensure_type<reference_type_data>(type_list<reference_t>{})}; return reference_type{ensure_type<reference_type_data>(type_list<reference_t>{})};
return type;
} }
template < void_kind Void > template < void_kind Void >
[[nodiscard]] void_type resolve_void_type() { [[nodiscard]] void_type resolve_void_type() {
using void_t = std::remove_cv_t<Void>; using void_t = std::remove_cv_t<Void>;
static void_type type{ensure_type<void_type_data>(type_list<void_t>{})}; return void_type{ensure_type<void_type_data>(type_list<void_t>{})};
return type;
} }
private: private:
@@ -4256,11 +4243,14 @@ namespace meta_hpp::detail
template < typename TypeData, typename... Args > template < typename TypeData, typename... Args >
TypeData* ensure_type(Args&&... args) { TypeData* ensure_type(Args&&... args) {
static auto data{std::make_unique<TypeData>(std::forward<Args>(args)...)}; static auto data = [this](Args&&... args) {
auto new_type_data = std::make_unique<TypeData>(META_HPP_FWD(args)...);
const locker lock; const locker lock;
types_.emplace_back(data.get()); types_.emplace_back(new_type_data.get());
return new_type_data;
}(META_HPP_FWD(args)...);
return data.get(); return data.get();
} }

View File

@@ -70,92 +70,79 @@ namespace meta_hpp::detail
template < array_kind Array > template < array_kind Array >
[[nodiscard]] array_type resolve_array_type() { [[nodiscard]] array_type resolve_array_type() {
using array_t = std::remove_cv_t<Array>; using array_t = std::remove_cv_t<Array>;
static array_type type{ensure_type<array_type_data>(type_list<array_t>{})}; return array_type{ensure_type<array_type_data>(type_list<array_t>{})};
return type;
} }
template < class_kind Class > template < class_kind Class >
[[nodiscard]] class_type resolve_class_type() { [[nodiscard]] class_type resolve_class_type() {
using class_t = std::remove_cv_t<Class>; using class_t = std::remove_cv_t<Class>;
static class_type type{ensure_type<class_type_data>(type_list<class_t>{})}; return class_type{ensure_type<class_type_data>(type_list<class_t>{})};
return type;
} }
template < class_kind Class, typename... Args > template < class_kind Class, typename... Args >
[[nodiscard]] constructor_type resolve_constructor_type() { [[nodiscard]] constructor_type resolve_constructor_type() {
using class_t = std::remove_cv_t<Class>; using class_t = std::remove_cv_t<Class>;
static constructor_type type{ensure_type<constructor_type_data>(type_list<class_t>{}, type_list<Args...>{})}; return constructor_type{ensure_type<constructor_type_data>(type_list<class_t>{}, type_list<Args...>{})};
return type;
} }
template < class_kind Class > template < class_kind Class >
[[nodiscard]] destructor_type resolve_destructor_type() { [[nodiscard]] destructor_type resolve_destructor_type() {
using class_t = std::remove_cv_t<Class>; using class_t = std::remove_cv_t<Class>;
static destructor_type type{ensure_type<destructor_type_data>(type_list<class_t>{})}; return destructor_type{ensure_type<destructor_type_data>(type_list<class_t>{})};
return type;
} }
template < enum_kind Enum > template < enum_kind Enum >
[[nodiscard]] enum_type resolve_enum_type() { [[nodiscard]] enum_type resolve_enum_type() {
using enum_t = std::remove_cv_t<Enum>; using enum_t = std::remove_cv_t<Enum>;
static enum_type type{ensure_type<enum_type_data>(type_list<enum_t>{})}; return enum_type{ensure_type<enum_type_data>(type_list<enum_t>{})};
return type;
} }
template < function_kind Function > template < function_kind Function >
[[nodiscard]] function_type resolve_function_type() { [[nodiscard]] function_type resolve_function_type() {
using function_t = std::remove_cv_t<Function>; using function_t = std::remove_cv_t<Function>;
static function_type type{ensure_type<function_type_data>(type_list<function_t>{})}; return function_type{ensure_type<function_type_data>(type_list<function_t>{})};
return type;
} }
template < member_pointer_kind Member > template < member_pointer_kind Member >
[[nodiscard]] member_type resolve_member_type() { [[nodiscard]] member_type resolve_member_type() {
using member_t = std::remove_cv_t<Member>; using member_t = std::remove_cv_t<Member>;
static member_type type{ensure_type<member_type_data>(type_list<member_t>{})}; return member_type{ensure_type<member_type_data>(type_list<member_t>{})};
return type;
} }
template < method_pointer_kind Method > template < method_pointer_kind Method >
[[nodiscard]] method_type resolve_method_type() { [[nodiscard]] method_type resolve_method_type() {
using method_t = std::remove_cv_t<Method>; using method_t = std::remove_cv_t<Method>;
static method_type type{ensure_type<method_type_data>(type_list<method_t>{})}; return method_type{ensure_type<method_type_data>(type_list<method_t>{})};
return type;
} }
template < nullptr_kind Nullptr > template < nullptr_kind Nullptr >
[[nodiscard]] nullptr_type resolve_nullptr_type() { [[nodiscard]] nullptr_type resolve_nullptr_type() {
using nullptr_t = std::remove_cv_t<Nullptr>; using nullptr_t = std::remove_cv_t<Nullptr>;
static nullptr_type type{ensure_type<nullptr_type_data>(type_list<nullptr_t>{})}; return nullptr_type{ensure_type<nullptr_type_data>(type_list<nullptr_t>{})};
return type;
} }
template < number_kind Number > template < number_kind Number >
[[nodiscard]] number_type resolve_number_type() { [[nodiscard]] number_type resolve_number_type() {
using number_t = std::remove_cv_t<Number>; using number_t = std::remove_cv_t<Number>;
static number_type type{ensure_type<number_type_data>(type_list<number_t>{})}; return number_type{ensure_type<number_type_data>(type_list<number_t>{})};
return type;
} }
template < pointer_kind Pointer > template < pointer_kind Pointer >
[[nodiscard]] pointer_type resolve_pointer_type() { [[nodiscard]] pointer_type resolve_pointer_type() {
using pointer_t = std::remove_cv_t<Pointer>; using pointer_t = std::remove_cv_t<Pointer>;
static pointer_type type{ensure_type<pointer_type_data>(type_list<pointer_t>{})}; return pointer_type{ensure_type<pointer_type_data>(type_list<pointer_t>{})};
return type;
} }
template < reference_kind Reference > template < reference_kind Reference >
[[nodiscard]] reference_type resolve_reference_type() { [[nodiscard]] reference_type resolve_reference_type() {
using reference_t = std::remove_cv_t<Reference>; using reference_t = std::remove_cv_t<Reference>;
static reference_type type{ensure_type<reference_type_data>(type_list<reference_t>{})}; return reference_type{ensure_type<reference_type_data>(type_list<reference_t>{})};
return type;
} }
template < void_kind Void > template < void_kind Void >
[[nodiscard]] void_type resolve_void_type() { [[nodiscard]] void_type resolve_void_type() {
using void_t = std::remove_cv_t<Void>; using void_t = std::remove_cv_t<Void>;
static void_type type{ensure_type<void_type_data>(type_list<void_t>{})}; return void_type{ensure_type<void_type_data>(type_list<void_t>{})};
return type;
} }
private: private:
@@ -163,11 +150,14 @@ namespace meta_hpp::detail
template < typename TypeData, typename... Args > template < typename TypeData, typename... Args >
TypeData* ensure_type(Args&&... args) { TypeData* ensure_type(Args&&... args) {
static auto data{std::make_unique<TypeData>(std::forward<Args>(args)...)}; static auto data = [this](Args&&... args) {
auto new_type_data = std::make_unique<TypeData>(META_HPP_FWD(args)...);
const locker lock; const locker lock;
types_.emplace_back(data.get()); types_.emplace_back(new_type_data.get());
return new_type_data;
}(META_HPP_FWD(args)...);
return data.get(); return data.get();
} }