universal resolve_poly_type for all types

This commit is contained in:
BlackMATov
2023-03-11 05:30:41 +07:00
parent 02f344197d
commit 7954964ed3
3 changed files with 118 additions and 30 deletions

View File

@@ -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