meta: refactor context argument as the last one
This commit is contained in:
@@ -1140,7 +1140,7 @@ public:
|
||||
*/
|
||||
[[nodiscard]] inline meta_type template_arg(const size_type index) const noexcept {
|
||||
const auto &ctx_TODO = internal::meta_context::from(locator<meta_ctx>::value_or());
|
||||
return index < template_arity() ? meta_type{node.templ.arg(ctx_TODO, index)} : meta_type{};
|
||||
return index < template_arity() ? meta_type{node.templ.arg(index, ctx_TODO)} : meta_type{};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -103,7 +103,7 @@ struct meta_template_node {
|
||||
|
||||
size_type arity{0u};
|
||||
meta_type_node (*type)(const meta_context &) noexcept {};
|
||||
meta_type_node (*arg)(const meta_context &, const size_type) noexcept {};
|
||||
meta_type_node (*arg)(const size_type, const meta_context &) noexcept {};
|
||||
};
|
||||
|
||||
struct meta_type_descriptor {
|
||||
@@ -140,7 +140,7 @@ template<typename Type>
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
[[nodiscard]] auto meta_arg_node(type_list<Args...>, const meta_context &context, [[maybe_unused]] const std::size_t index) noexcept {
|
||||
[[nodiscard]] auto meta_arg_node(type_list<Args...>, [[maybe_unused]] const std::size_t index, const meta_context &context) noexcept {
|
||||
std::size_t pos{};
|
||||
meta_type_node (*value)(const meta_context &) noexcept = nullptr;
|
||||
((value = (pos++ == index ? &resolve<std::remove_cv_t<std::remove_reference_t<Args>>> : value)), ...);
|
||||
@@ -150,7 +150,7 @@ template<typename... Args>
|
||||
|
||||
template<typename Args>
|
||||
[[nodiscard]] auto meta_arg_node_TODO(Args, const std::size_t index) noexcept {
|
||||
return meta_arg_node(Args{}, meta_context::from(locator<meta_ctx>::value_or()), index);
|
||||
return meta_arg_node(Args{}, index, meta_context::from(locator<meta_ctx>::value_or()));
|
||||
}
|
||||
|
||||
[[nodiscard]] inline const void *try_cast(const meta_type_node &from, const meta_type_node &to, const void *instance) noexcept {
|
||||
@@ -169,7 +169,7 @@ template<typename Args>
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline const meta_type_node *try_resolve(const meta_context &context, const type_info &info) noexcept {
|
||||
[[nodiscard]] inline const meta_type_node *try_resolve(const type_info &info, const meta_context &context) noexcept {
|
||||
const auto it = context.value.find(info.hash());
|
||||
return it != context.value.end() ? &it->second : nullptr;
|
||||
}
|
||||
@@ -178,7 +178,7 @@ template<typename Type>
|
||||
[[nodiscard]] meta_type_node resolve(const meta_context &context) noexcept {
|
||||
static_assert(std::is_same_v<Type, std::remove_const_t<std::remove_reference_t<Type>>>, "Invalid type");
|
||||
|
||||
if(auto *elem = try_resolve(context, type_id<Type>()); elem) {
|
||||
if(auto *elem = try_resolve(type_id<Type>(), context); elem) {
|
||||
return *elem;
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ template<typename Type>
|
||||
node.templ = meta_template_node{
|
||||
meta_template_traits<Type>::args_type::size,
|
||||
&resolve<typename meta_template_traits<Type>::class_type>,
|
||||
+[](const meta_context &context, const std::size_t index) noexcept { return meta_arg_node(typename meta_template_traits<Type>::args_type{}, context, index); }};
|
||||
+[](const std::size_t index, const meta_context &context) noexcept { return meta_arg_node(typename meta_template_traits<Type>::args_type{}, index, context); }};
|
||||
}
|
||||
|
||||
return node;
|
||||
|
||||
@@ -18,46 +18,28 @@ namespace entt {
|
||||
* @return The meta type associated with the given type, if any.
|
||||
*/
|
||||
template<typename Type>
|
||||
[[nodiscard]] meta_type resolve(const meta_ctx &context) noexcept {
|
||||
[[nodiscard]] meta_type resolve(const meta_ctx &context = locator<meta_ctx>::value_or()) noexcept {
|
||||
auto &&ctx = internal::meta_context::from(context);
|
||||
return internal::resolve<std::remove_cv_t<std::remove_reference_t<Type>>>(ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the meta type associated with a given type.
|
||||
* @tparam Type Type to use to search for a meta type.
|
||||
* @return The meta type associated with the given type, if any.
|
||||
*/
|
||||
template<typename Type>
|
||||
[[nodiscard]] meta_type resolve() noexcept {
|
||||
return resolve<Type>(locator<meta_ctx>::value_or());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns a range to use to visit all meta types.
|
||||
* @param context The context from which to search for meta types.
|
||||
* @return An iterable range to use to visit all meta types.
|
||||
*/
|
||||
[[nodiscard]] inline meta_range<meta_type, typename decltype(internal::meta_context::value)::const_iterator> resolve(const meta_ctx &context) noexcept {
|
||||
[[nodiscard]] inline meta_range<meta_type, typename decltype(internal::meta_context::value)::const_iterator> resolve(const meta_ctx &context = locator<meta_ctx>::value_or()) noexcept {
|
||||
auto &&ctx = internal::meta_context::from(context);
|
||||
return {ctx.value.cbegin(), ctx.value.cend()};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns a range to use to visit all meta types.
|
||||
* @return An iterable range to use to visit all meta types.
|
||||
*/
|
||||
[[nodiscard]] inline meta_range<meta_type, typename decltype(internal::meta_context::value)::const_iterator> resolve() noexcept {
|
||||
return resolve(locator<meta_ctx>::value_or());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the meta type associated with a given identifier, if any.
|
||||
* @param context The context from which to search for meta types.
|
||||
* @param id Unique identifier.
|
||||
* @param context The context from which to search for meta types.
|
||||
* @return The meta type associated with the given identifier, if any.
|
||||
*/
|
||||
[[nodiscard]] inline meta_type resolve(const meta_ctx &context, const id_type id) noexcept {
|
||||
[[nodiscard]] inline meta_type resolve(const id_type id, const meta_ctx &context = locator<meta_ctx>::value_or()) noexcept {
|
||||
for(auto &&curr: resolve(context)) {
|
||||
if(curr.second.id() == id) {
|
||||
return curr.second;
|
||||
@@ -67,36 +49,18 @@ template<typename Type>
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the meta type associated with a given identifier, if any.
|
||||
* @param id Unique identifier.
|
||||
* @return The meta type associated with the given identifier, if any.
|
||||
*/
|
||||
[[nodiscard]] inline meta_type resolve(const id_type id) noexcept {
|
||||
return resolve(locator<meta_ctx>::value_or(), id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the meta type associated with a given type info object.
|
||||
* @param info The type info object of the requested type.
|
||||
* @param context The context from which to search for meta types.
|
||||
* @param info The type info object of the requested type.
|
||||
* @return The meta type associated with the given type info object, if any.
|
||||
*/
|
||||
[[nodiscard]] inline meta_type resolve(const meta_ctx &context, const type_info &info) noexcept {
|
||||
[[nodiscard]] inline meta_type resolve(const type_info &info, const meta_ctx &context = locator<meta_ctx>::value_or()) noexcept {
|
||||
auto &&ctx = internal::meta_context::from(context);
|
||||
const auto *elem = internal::try_resolve(ctx, info);
|
||||
const auto *elem = internal::try_resolve(info, ctx);
|
||||
return elem ? *elem : meta_type{};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the meta type associated with a given type info object.
|
||||
* @param info The type info object of the requested type.
|
||||
* @return The meta type associated with the given type info object, if any.
|
||||
*/
|
||||
[[nodiscard]] inline meta_type resolve(const type_info &info) noexcept {
|
||||
return resolve(locator<meta_ctx>::value_or(), info);
|
||||
}
|
||||
|
||||
} // namespace entt
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user