From 2739964a1f15b97aea79bf60ce71c98c276a5fc0 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Mon, 10 Oct 2022 15:04:29 +0200 Subject: [PATCH] meta: make meta_dispatch support and use meta contexts --- src/entt/meta/utility.hpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/entt/meta/utility.hpp b/src/entt/meta/utility.hpp index 3e8b9e963..2881c5d9a 100644 --- a/src/entt/meta/utility.hpp +++ b/src/entt/meta/utility.hpp @@ -152,24 +152,37 @@ using meta_function_helper_t = typename meta_function_helper::t * @brief Wraps a value depending on the given policy. * @tparam Policy Optional policy (no policy set by default). * @tparam Type Type of value to wrap. + * @param ctx The context from which to search for meta types. * @param value Value to wrap. * @return A meta any containing the returned value, if any. */ template -meta_any meta_dispatch([[maybe_unused]] Type &&value) { +meta_any meta_dispatch(const meta_ctx &ctx, [[maybe_unused]] Type &&value) { if constexpr(std::is_same_v) { - return meta_any{std::in_place_type}; + return meta_any{ctx, std::in_place_type}; } else if constexpr(std::is_same_v) { - return meta_any{std::in_place_type, value}; + return meta_any{ctx, std::in_place_type, value}; } else if constexpr(std::is_same_v) { static_assert(std::is_lvalue_reference_v, "Invalid type"); - return meta_any{std::in_place_type &>, std::as_const(value)}; + return meta_any{ctx, std::in_place_type &>, std::as_const(value)}; } else { static_assert(std::is_same_v, "Policy not supported"); - return meta_any{std::forward(value)}; + return meta_any{ctx, std::forward(value)}; } } +/** + * @brief Wraps a value depending on the given policy. + * @tparam Policy Optional policy (no policy set by default). + * @tparam Type Type of value to wrap. + * @param value Value to wrap. + * @return A meta any containing the returned value, if any. + */ +template +meta_any meta_dispatch(Type &&value) { + return meta_dispatch(locator::value_or(), std::forward(value)); +} + /** * @brief Returns the meta type of the i-th element of a list of arguments. * @tparam Type Type list of the actual types of arguments.