meta: template info review

This commit is contained in:
Michele Caini
2021-05-14 16:51:29 +02:00
parent 266dd02ef5
commit 93fc08df45
3 changed files with 24 additions and 24 deletions

View File

@@ -1245,7 +1245,7 @@ public:
* false otherwise.
*/
[[nodiscard]] bool is_template_specialization() const ENTT_NOEXCEPT {
return node->template_info.is_template_specialization;
return (node->templ != nullptr);
}
/**
@@ -1253,7 +1253,7 @@ public:
* @return The number of template arguments, if any.
*/
[[nodiscard]] size_type template_arity() const ENTT_NOEXCEPT {
return node->template_info.arity;
return node->templ ? node->templ->arity : size_type{};
}
/**
@@ -1264,7 +1264,7 @@ public:
* @return The tag for the class template of the underlying type.
*/
[[nodiscard]] inline meta_type template_type() const ENTT_NOEXCEPT {
return is_template_specialization() ? node->template_info.type() : meta_type{};
return node->templ ? node->templ->type() : meta_type{};
}
/**
@@ -1273,7 +1273,7 @@ public:
* @return The type of the i-th template argument of a type.
*/
[[nodiscard]] inline meta_type template_arg(size_type index) const ENTT_NOEXCEPT {
return index < template_arity() ? node->template_info.arg(index) : meta_type{};
return index < template_arity() ? node->templ->arg(index) : meta_type{};
}
/**

View File

@@ -95,9 +95,8 @@ struct meta_func_node {
};
struct meta_template_info {
struct meta_template_node {
using size_type = std::size_t;
const bool is_template_specialization;
const size_type arity;
meta_type_node *(* const type)() ENTT_NOEXCEPT;
meta_type_node *(* const arg)(const size_type) ENTT_NOEXCEPT;
@@ -125,11 +124,11 @@ struct meta_type_node {
const bool is_pointer_like;
const bool is_sequence_container;
const bool is_associative_container;
const meta_template_info template_info;
const size_type rank;
size_type(* const extent)(const size_type) ENTT_NOEXCEPT ;
meta_type_node *(* const remove_pointer)() ENTT_NOEXCEPT;
meta_type_node *(* const remove_extent)() ENTT_NOEXCEPT;
const meta_template_node *const templ;
meta_ctor_node * const def_ctor;
meta_ctor_node *ctor{nullptr};
meta_base_node *base{nullptr};
@@ -193,18 +192,19 @@ class ENTT_API meta_node {
}
}
[[nodiscard]] static meta_template_info meta_template_descriptor() ENTT_NOEXCEPT {
[[nodiscard]] static meta_template_node * meta_template_info() ENTT_NOEXCEPT {
if constexpr(is_complete_v<meta_template_traits<Type>>) {
return {
true,
static meta_template_node node{
meta_template_traits<Type>::args_type::size,
&meta_node<typename meta_template_traits<Type>::class_type>::resolve,
[](const std::size_t index) ENTT_NOEXCEPT {
return meta_arg_node(typename meta_template_traits<Type>::args_type{}, index);
}
};
return &node;
} else {
return { false, 0u, nullptr, nullptr };
return nullptr;
}
}
@@ -230,11 +230,11 @@ public:
is_meta_pointer_like_v<Type>,
is_complete_v<meta_sequence_container_traits<Type>>,
is_complete_v<meta_associative_container_traits<Type>>,
meta_template_descriptor(),
std::rank_v<Type>,
[](meta_type_node::size_type dim) ENTT_NOEXCEPT { return extent(dim, std::make_index_sequence<std::rank_v<Type>>{}); },
&meta_node<std::remove_cv_t<std::remove_reference_t<std::remove_pointer_t<Type>>>>::resolve,
&meta_node<std::remove_cv_t<std::remove_reference_t<std::remove_extent_t<Type>>>>::resolve,
meta_template_info(),
meta_default_constructor(&node),
meta_default_constructor(&node)
};

View File

@@ -121,22 +121,22 @@ using meta_function_helper_t = typename meta_function_helper<Type, Candidate>::t
/**
* @brief Wraps a value depending on the given policy.
* @tparam Policy Optional policy (no policy set by default).
* @tparam Type Optional type of value to wrap.
* @param value Optional value to wrap.
* @tparam Type Type of value to wrap.
* @param value Value to wrap.
* @return A meta any containing the returned value, if any.
*/
template<typename Policy = as_is_t, typename... Type>
meta_any meta_dispatch([[maybe_unused]] Type &&... value) {
if constexpr(std::is_same_v<Policy, as_void_t> || !sizeof...(Type)) {
template<typename Policy = as_is_t, typename Type>
meta_any meta_dispatch([[maybe_unused]] Type &&value) {
if constexpr(std::is_same_v<Policy, as_void_t>) {
return meta_any{std::in_place_type<void>};
} else if constexpr(std::is_same_v<Policy, as_ref_t>) {
return meta_any{std::in_place_type<Type...>, std::forward<Type>(value)...};
return meta_any{std::in_place_type<Type>, std::forward<Type>(value)};
} else if constexpr(std::is_same_v<Policy, as_cref_t>) {
static_assert(std::is_lvalue_reference_v<Type...>, "Invalid type");
return meta_any{std::in_place_type<const std::remove_reference_t<Type> &...>, std::as_const(value)...};
static_assert(std::is_lvalue_reference_v<Type>, "Invalid type");
return meta_any{std::in_place_type<const std::remove_reference_t<Type> &>, std::as_const(value)};
} else {
static_assert(std::is_same_v<Policy, as_is_t>, "Policy not supported");
return meta_any{std::forward<Type>(value)...};
return meta_any{std::forward<Type>(value)};
}
}
@@ -257,14 +257,14 @@ template<typename Type, auto Candidate, typename Policy = as_is_t, std::size_t..
if constexpr(std::is_member_function_pointer_v<decltype(Candidate)>) {
if constexpr(std::is_void_v<typename descriptor::return_type>) {
(std::forward<decltype(maybe_clazz)>(maybe_clazz).*Candidate)(std::forward<decltype(other)>(other)...);
return meta_dispatch();
return meta_any{std::in_place_type<void>};
} else {
return meta_dispatch<Policy>((std::forward<decltype(maybe_clazz)>(maybe_clazz).*Candidate)(std::forward<decltype(other)>(other)...));
}
} else {
if constexpr(std::is_void_v<typename descriptor::return_type>) {
Candidate(std::forward<decltype(maybe_clazz)>(maybe_clazz), std::forward<decltype(other)>(other)...);
return meta_dispatch();
return meta_any{std::in_place_type<void>};
} else {
return meta_dispatch<Policy>(Candidate(std::forward<decltype(maybe_clazz)>(maybe_clazz), std::forward<decltype(other)>(other)...));
}
@@ -322,7 +322,7 @@ template<typename Type, auto Candidate, typename Policy = as_is_t>
if constexpr(std::is_invocable_v<decltype(Candidate)>) {
if constexpr(std::is_void_v<decltype(Candidate())>) {
Candidate();
return meta_dispatch();
return meta_any{std::in_place_type<void>};
} else {
return meta_dispatch<Policy>(Candidate());
}