mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-14 11:40:35 +07:00
universal resolve_poly_type for all types
This commit is contained in:
@@ -52,6 +52,28 @@ namespace meta_hpp
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
{
|
||||
template < typename T >
|
||||
[[nodiscard]] auto resolve_poly_type(T&& from) {
|
||||
using namespace detail;
|
||||
|
||||
using raw_type = std::remove_cvref_t<T>;
|
||||
type_registry& registry = type_registry::instance();
|
||||
|
||||
if constexpr ( std::is_class_v<raw_type> ) {
|
||||
static_assert(
|
||||
detail::check_poly_info_enabled<raw_type>,
|
||||
"The class doesn't support polymorphic type resolving. Use the META_HPP_ENABLE_POLY_INFO macro to fix it."
|
||||
);
|
||||
return from.get_most_derived_poly_info(registry).type;
|
||||
} else {
|
||||
(void)from;
|
||||
return registry.resolve_type<raw_type>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
{
|
||||
template < detail::class_kind Class, typename... Args >
|
||||
@@ -67,21 +89,6 @@ namespace meta_hpp
|
||||
type_registry& registry = type_registry::instance();
|
||||
return registry.resolve_destructor_type<Class>();
|
||||
}
|
||||
|
||||
template < typename From >
|
||||
requires std::is_class_v<std::remove_reference_t<From>>
|
||||
[[nodiscard]] class_type resolve_poly_type(From&& from) {
|
||||
using from_data_type = std::remove_reference_t<From>;
|
||||
|
||||
static_assert(
|
||||
detail::check_poly_info_enabled<from_data_type>,
|
||||
"The type doesn't support ucasts. Use the META_HPP_ENABLE_POLY_INFO macro to fix it."
|
||||
);
|
||||
|
||||
using namespace detail;
|
||||
type_registry& registry = type_registry::instance();
|
||||
return from.get_most_derived_poly_info(registry).type;
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
|
||||
Reference in New Issue
Block a user