|
|
@@ -9,7 +9,6 @@
|
|
|
#include "../locator/locator.hpp"
|
|
|
#include "meta.hpp"
|
|
|
#include "node.hpp"
|
|
|
-#include "policy.hpp"
|
|
|
|
|
|
namespace entt {
|
|
|
|
|
|
@@ -77,7 +76,7 @@ template<typename Type, typename Ret, typename Class>
|
|
|
struct meta_function_descriptor<Type, Ret Class::*>
|
|
|
: meta_function_descriptor_traits<
|
|
|
Ret &,
|
|
|
- std::conditional_t<std::is_base_of_v<Class, Type>, type_list<>, type_list<Class &>>,
|
|
|
+ std::conditional_t<std::is_base_of_v<Class, Type>, type_list<Ret>, type_list<Class &, Ret>>,
|
|
|
!std::is_base_of_v<Class, Type>,
|
|
|
false> {};
|
|
|
|
|
|
@@ -152,73 +151,66 @@ template<typename Type, typename Candidate>
|
|
|
using meta_function_helper_t = typename meta_function_helper<Type, Candidate>::type;
|
|
|
|
|
|
/**
|
|
|
- * @brief Wraps a value depending on the given policy.
|
|
|
+ * @brief Wraps a value and returns it.
|
|
|
*
|
|
|
* This function always returns a wrapped value in the requested context.<br/>
|
|
|
* Therefore, if the passed value is itself a wrapped object with a different
|
|
|
* context, it undergoes a rebinding to the requested context.
|
|
|
*
|
|
|
- * @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<typename Policy = as_is_t, typename Type>
|
|
|
-[[nodiscard]] std::enable_if_t<is_meta_policy_v<Policy>, meta_any> meta_dispatch(const meta_ctx &ctx, [[maybe_unused]] Type &&value) {
|
|
|
- if constexpr(std::is_same_v<Policy, as_void_t>) {
|
|
|
- return meta_any{ctx, std::in_place_type<void>};
|
|
|
- } else if constexpr(std::is_same_v<Policy, as_ref_t>) {
|
|
|
- return meta_any{ctx, std::in_place_type<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{ctx, std::in_place_type<const std::remove_reference_t<Type> &>, std::as_const(value)};
|
|
|
+template<typename Type>
|
|
|
+[[nodiscard]] meta_any meta_dispatch(const meta_ctx &ctx, [[maybe_unused]] Type &&value) {
|
|
|
+ if constexpr(std::is_lvalue_reference_v<Type> && !std::is_same_v<std::remove_const_t<std::remove_reference_t<Type>>, meta_any>) {
|
|
|
+ return meta_any{ctx, std::in_place_type<Type>, std::forward<Type>(value)};
|
|
|
} else {
|
|
|
return meta_any{ctx, std::forward<Type>(value)};
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @brief Wraps a value depending on the given policy.
|
|
|
- * @tparam Policy Optional policy (no policy set by default).
|
|
|
+ * @brief Wraps a value and returns it.
|
|
|
* @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>
|
|
|
-[[nodiscard]] std::enable_if_t<is_meta_policy_v<Policy>, meta_any> meta_dispatch(Type &&value) {
|
|
|
- return meta_dispatch<Policy, Type>(locator<meta_ctx>::value_or(), std::forward<Type>(value));
|
|
|
+template<typename Type>
|
|
|
+[[nodiscard]] meta_any meta_dispatch(Type &&value) {
|
|
|
+ return meta_dispatch<Type>(locator<meta_ctx>::value_or(), std::forward<Type>(value));
|
|
|
}
|
|
|
|
|
|
/*! @cond TURN_OFF_DOXYGEN */
|
|
|
namespace internal {
|
|
|
|
|
|
-template<typename Policy, typename Candidate, typename... Args>
|
|
|
+template<typename Candidate, typename... Args>
|
|
|
[[nodiscard]] meta_any meta_invoke_with_args(const meta_ctx &ctx, Candidate &&candidate, Args &&...args) {
|
|
|
if constexpr(std::is_void_v<decltype(std::invoke(std::forward<Candidate>(candidate), args...))>) {
|
|
|
std::invoke(std::forward<Candidate>(candidate), args...);
|
|
|
return meta_any{ctx, std::in_place_type<void>};
|
|
|
} else {
|
|
|
- return meta_dispatch<Policy>(ctx, std::invoke(std::forward<Candidate>(candidate), args...));
|
|
|
+ return meta_dispatch(ctx, std::invoke(std::forward<Candidate>(candidate), args...));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-template<typename Type, typename Policy, typename Candidate, std::size_t... Index>
|
|
|
+template<typename Type, typename Candidate, std::size_t... Index>
|
|
|
[[nodiscard]] meta_any meta_invoke(meta_handle &instance, Candidate &&candidate, [[maybe_unused]] meta_any *const args, std::index_sequence<Index...>) {
|
|
|
using descriptor = meta_function_helper_t<Type, std::remove_reference_t<Candidate>>;
|
|
|
|
|
|
// NOLINTBEGIN(cppcoreguidelines-pro-bounds-pointer-arithmetic) - waiting for C++20 (and std::span)
|
|
|
if constexpr(std::is_invocable_v<std::remove_reference_t<Candidate>, const Type &, type_list_element_t<Index, typename descriptor::args_type>...>) {
|
|
|
if(const auto *const clazz = instance->try_cast<const Type>(); clazz && ((args + Index)->allow_cast<type_list_element_t<Index, typename descriptor::args_type>>() && ...)) {
|
|
|
- return meta_invoke_with_args<Policy>(instance->context(), std::forward<Candidate>(candidate), *clazz, (args + Index)->cast<type_list_element_t<Index, typename descriptor::args_type>>()...);
|
|
|
+ return meta_invoke_with_args(instance->context(), std::forward<Candidate>(candidate), *clazz, (args + Index)->cast<type_list_element_t<Index, typename descriptor::args_type>>()...);
|
|
|
}
|
|
|
} else if constexpr(std::is_invocable_v<std::remove_reference_t<Candidate>, Type &, type_list_element_t<Index, typename descriptor::args_type>...>) {
|
|
|
if(auto *const clazz = instance->try_cast<Type>(); clazz && ((args + Index)->allow_cast<type_list_element_t<Index, typename descriptor::args_type>>() && ...)) {
|
|
|
- return meta_invoke_with_args<Policy>(instance->context(), std::forward<Candidate>(candidate), *clazz, (args + Index)->cast<type_list_element_t<Index, typename descriptor::args_type>>()...);
|
|
|
+ return meta_invoke_with_args(instance->context(), std::forward<Candidate>(candidate), *clazz, (args + Index)->cast<type_list_element_t<Index, typename descriptor::args_type>>()...);
|
|
|
}
|
|
|
} else {
|
|
|
if(((args + Index)->allow_cast<type_list_element_t<Index, typename descriptor::args_type>>() && ...)) {
|
|
|
- return meta_invoke_with_args<Policy>(instance->context(), std::forward<Candidate>(candidate), (args + Index)->cast<type_list_element_t<Index, typename descriptor::args_type>>()...);
|
|
|
+ return meta_invoke_with_args(instance->context(), std::forward<Candidate>(candidate), (args + Index)->cast<type_list_element_t<Index, typename descriptor::args_type>>()...);
|
|
|
}
|
|
|
}
|
|
|
// NOLINTEND(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
|
|
@@ -309,23 +301,22 @@ template<typename Type, auto Data>
|
|
|
* @brief Gets the value of a given variable.
|
|
|
* @tparam Type Reflected type to which the variable is associated.
|
|
|
* @tparam Data The actual variable to get.
|
|
|
- * @tparam Policy Optional policy (no policy set by default).
|
|
|
* @param instance An opaque instance of the underlying type, if required.
|
|
|
* @return A meta any containing the value of the underlying variable.
|
|
|
*/
|
|
|
-template<typename Type, auto Data, typename Policy = as_is_t>
|
|
|
-[[nodiscard]] std::enable_if_t<is_meta_policy_v<Policy>, meta_any> meta_getter(meta_handle instance) {
|
|
|
+template<typename Type, auto Data>
|
|
|
+[[nodiscard]] meta_any meta_getter(meta_handle instance) {
|
|
|
if constexpr(std::is_member_pointer_v<decltype(Data)> || std::is_function_v<std::remove_reference_t<std::remove_pointer_t<decltype(Data)>>>) {
|
|
|
if constexpr(!std::is_array_v<std::remove_cv_t<std::remove_reference_t<std::invoke_result_t<decltype(Data), Type &>>>>) {
|
|
|
if constexpr(std::is_invocable_v<decltype(Data), Type &>) {
|
|
|
if(auto *clazz = instance->try_cast<Type>(); clazz) {
|
|
|
- return meta_dispatch<Policy>(instance->context(), std::invoke(Data, *clazz));
|
|
|
+ return internal::meta_invoke_with_args(instance->context(), Data, *clazz);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if constexpr(std::is_invocable_v<decltype(Data), const Type &>) {
|
|
|
if(auto *fallback = instance->try_cast<const Type>(); fallback) {
|
|
|
- return meta_dispatch<Policy>(instance->context(), std::invoke(Data, *fallback));
|
|
|
+ return internal::meta_invoke_with_args(instance->context(), Data, *fallback);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -335,40 +326,38 @@ template<typename Type, auto Data, typename Policy = as_is_t>
|
|
|
if constexpr(std::is_array_v<std::remove_pointer_t<decltype(Data)>>) {
|
|
|
return meta_any{meta_ctx_arg, instance->context()};
|
|
|
} else {
|
|
|
- return meta_dispatch<Policy>(instance->context(), *Data);
|
|
|
+ return meta_dispatch(instance->context(), *Data);
|
|
|
}
|
|
|
} else {
|
|
|
- return meta_dispatch<Policy>(instance->context(), Data);
|
|
|
+ return meta_dispatch(instance->context(), Data);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @brief Tries to _invoke_ an object given a list of erased parameters.
|
|
|
* @tparam Type Reflected type to which the object to _invoke_ is associated.
|
|
|
- * @tparam Policy Optional policy (no policy set by default).
|
|
|
* @tparam Candidate The type of the actual object to _invoke_.
|
|
|
* @param instance An opaque instance of the underlying type, if required.
|
|
|
* @param candidate The actual object to _invoke_.
|
|
|
* @param args Parameters to use to _invoke_ the object.
|
|
|
* @return A meta any containing the returned value, if any.
|
|
|
*/
|
|
|
-template<typename Type, typename Policy = as_is_t, typename Candidate>
|
|
|
-[[nodiscard]] std::enable_if_t<is_meta_policy_v<Policy>, meta_any> meta_invoke(meta_handle instance, Candidate &&candidate, meta_any *const args) {
|
|
|
- return internal::meta_invoke<Type, Policy>(instance, std::forward<Candidate>(candidate), args, std::make_index_sequence<meta_function_helper_t<Type, std::remove_reference_t<Candidate>>::args_type::size>{});
|
|
|
+template<typename Type, typename Candidate>
|
|
|
+[[nodiscard]] meta_any meta_invoke(meta_handle instance, Candidate &&candidate, meta_any *const args) {
|
|
|
+ return internal::meta_invoke<Type>(instance, std::forward<Candidate>(candidate), args, std::make_index_sequence<meta_function_helper_t<Type, std::remove_reference_t<Candidate>>::args_type::size>{});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @brief Tries to invoke a function given a list of erased parameters.
|
|
|
* @tparam Type Reflected type to which the function is associated.
|
|
|
* @tparam Candidate The actual function to invoke.
|
|
|
- * @tparam Policy Optional policy (no policy set by default).
|
|
|
* @param instance An opaque instance of the underlying type, if required.
|
|
|
* @param args Parameters to use to invoke the function.
|
|
|
* @return A meta any containing the returned value, if any.
|
|
|
*/
|
|
|
-template<typename Type, auto Candidate, typename Policy = as_is_t>
|
|
|
-[[nodiscard]] std::enable_if_t<is_meta_policy_v<Policy>, meta_any> meta_invoke(meta_handle instance, meta_any *const args) {
|
|
|
- return internal::meta_invoke<Type, Policy>(instance, Candidate, args, std::make_index_sequence<meta_function_helper_t<Type, std::remove_reference_t<decltype(Candidate)>>::args_type::size>{});
|
|
|
+template<typename Type, auto Candidate>
|
|
|
+[[nodiscard]] meta_any meta_invoke(meta_handle instance, meta_any *const args) {
|
|
|
+ return internal::meta_invoke<Type>(instance, Candidate, args, std::make_index_sequence<meta_function_helper_t<Type, std::remove_reference_t<decltype(Candidate)>>::args_type::size>{});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -409,37 +398,35 @@ template<typename Type, typename... Args>
|
|
|
* It's up to the caller to bind the arguments to the right context(s).
|
|
|
*
|
|
|
* @tparam Type Reflected type to which the object to _invoke_ is associated.
|
|
|
- * @tparam Policy Optional policy (no policy set by default).
|
|
|
* @tparam Candidate The type of the actual object to _invoke_.
|
|
|
* @param ctx The context from which to search for meta types.
|
|
|
* @param candidate The actual object to _invoke_.
|
|
|
* @param args Parameters to use to _invoke_ the object.
|
|
|
* @return A meta any containing the returned value, if any.
|
|
|
*/
|
|
|
-template<typename Type, typename Policy = as_is_t, typename Candidate>
|
|
|
+template<typename Type, typename Candidate>
|
|
|
[[nodiscard]] meta_any meta_construct(const meta_ctx &ctx, Candidate &&candidate, meta_any *const args) {
|
|
|
if constexpr(meta_function_helper_t<Type, Candidate>::is_static || std::is_class_v<std::remove_cv_t<std::remove_reference_t<Candidate>>>) {
|
|
|
meta_handle placeholder{meta_ctx_arg, ctx};
|
|
|
- return internal::meta_invoke<Type, Policy>(placeholder, std::forward<Candidate>(candidate), args, std::make_index_sequence<meta_function_helper_t<Type, std::remove_reference_t<Candidate>>::args_type::size>{});
|
|
|
+ return internal::meta_invoke<Type>(placeholder, std::forward<Candidate>(candidate), args, std::make_index_sequence<meta_function_helper_t<Type, std::remove_reference_t<Candidate>>::args_type::size>{});
|
|
|
} else {
|
|
|
meta_handle target{*args};
|
|
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - waiting for C++20 (and std::span)
|
|
|
- return internal::meta_invoke<Type, Policy>(target, std::forward<Candidate>(candidate), args + 1u, std::make_index_sequence<meta_function_helper_t<Type, std::remove_reference_t<Candidate>>::args_type::size>{});
|
|
|
+ return internal::meta_invoke<Type>(target, std::forward<Candidate>(candidate), args + 1u, std::make_index_sequence<meta_function_helper_t<Type, std::remove_reference_t<Candidate>>::args_type::size>{});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @brief Tries to construct an instance given a list of erased parameters.
|
|
|
* @tparam Type Reflected type to which the object to _invoke_ is associated.
|
|
|
- * @tparam Policy Optional policy (no policy set by default).
|
|
|
* @tparam Candidate The type of the actual object to _invoke_.
|
|
|
* @param candidate The actual object to _invoke_.
|
|
|
* @param args Parameters to use to _invoke_ the object.
|
|
|
* @return A meta any containing the returned value, if any.
|
|
|
*/
|
|
|
-template<typename Type, typename Policy = as_is_t, typename Candidate>
|
|
|
-[[nodiscard]] std::enable_if_t<is_meta_policy_v<Policy>, meta_any> meta_construct(Candidate &&candidate, meta_any *const args) {
|
|
|
- return meta_construct<Type, Policy>(locator<meta_ctx>::value_or(), std::forward<Candidate>(candidate), args);
|
|
|
+template<typename Type, typename Candidate>
|
|
|
+[[nodiscard]] meta_any meta_construct(Candidate &&candidate, meta_any *const args) {
|
|
|
+ return meta_construct<Type>(locator<meta_ctx>::value_or(), std::forward<Candidate>(candidate), args);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -451,27 +438,25 @@ template<typename Type, typename Policy = as_is_t, typename Candidate>
|
|
|
*
|
|
|
* @tparam Type Reflected type to which the function is associated.
|
|
|
* @tparam Candidate The actual function to invoke.
|
|
|
- * @tparam Policy Optional policy (no policy set by default).
|
|
|
* @param ctx The context from which to search for meta types.
|
|
|
* @param args Parameters to use to invoke the function.
|
|
|
* @return A meta any containing the returned value, if any.
|
|
|
*/
|
|
|
-template<typename Type, auto Candidate, typename Policy = as_is_t>
|
|
|
-[[nodiscard]] std::enable_if_t<is_meta_policy_v<Policy>, meta_any> meta_construct(const meta_ctx &ctx, meta_any *const args) {
|
|
|
- return meta_construct<Type, Policy>(ctx, Candidate, args);
|
|
|
+template<typename Type, auto Candidate>
|
|
|
+[[nodiscard]] meta_any meta_construct(const meta_ctx &ctx, meta_any *const args) {
|
|
|
+ return meta_construct<Type>(ctx, Candidate, args);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @brief Tries to construct an instance given a list of erased parameters.
|
|
|
* @tparam Type Reflected type to which the function is associated.
|
|
|
* @tparam Candidate The actual function to invoke.
|
|
|
- * @tparam Policy Optional policy (no policy set by default).
|
|
|
* @param args Parameters to use to invoke the function.
|
|
|
* @return A meta any containing the returned value, if any.
|
|
|
*/
|
|
|
-template<typename Type, auto Candidate, typename Policy = as_is_t>
|
|
|
-[[nodiscard]] std::enable_if_t<is_meta_policy_v<Policy>, meta_any> meta_construct(meta_any *const args) {
|
|
|
- return meta_construct<Type, Candidate, Policy>(locator<meta_ctx>::value_or(), args);
|
|
|
+template<typename Type, auto Candidate>
|
|
|
+[[nodiscard]] meta_any meta_construct(meta_any *const args) {
|
|
|
+ return meta_construct<Type, Candidate>(locator<meta_ctx>::value_or(), args);
|
|
|
}
|
|
|
|
|
|
} // namespace entt
|