stl: std::remove_reference_t
This commit is contained in:
@@ -138,7 +138,7 @@ class basic_any: private internal::basic_any_storage<Len, Align> {
|
||||
this->instance = nullptr;
|
||||
} else if constexpr(stl::is_lvalue_reference_v<Type>) {
|
||||
deleter = nullptr;
|
||||
mode = std::is_const_v<std::remove_reference_t<Type>> ? any_policy::cref : any_policy::ref;
|
||||
mode = std::is_const_v<stl::remove_reference_t<Type>> ? any_policy::cref : any_policy::ref;
|
||||
static_assert((stl::is_lvalue_reference_v<Args> && ...) && (sizeof...(Args) == 1u), "Invalid arguments");
|
||||
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
|
||||
this->instance = (std::addressof(args), ...);
|
||||
@@ -542,7 +542,7 @@ private:
|
||||
*/
|
||||
template<typename Type, std::size_t Len, std::size_t Align>
|
||||
[[nodiscard]] std::remove_const_t<Type> any_cast(const basic_any<Len, Align> &data) noexcept {
|
||||
const auto *const instance = any_cast<std::remove_reference_t<Type>>(&data);
|
||||
const auto *const instance = any_cast<stl::remove_reference_t<Type>>(&data);
|
||||
ENTT_ASSERT(instance, "Invalid instance");
|
||||
return static_cast<Type>(*instance);
|
||||
}
|
||||
@@ -551,7 +551,7 @@ template<typename Type, std::size_t Len, std::size_t Align>
|
||||
template<typename Type, std::size_t Len, std::size_t Align>
|
||||
[[nodiscard]] std::remove_const_t<Type> any_cast(basic_any<Len, Align> &data) noexcept {
|
||||
// forces const on non-reference types to make them work also with wrappers for const references
|
||||
auto *const instance = any_cast<std::remove_reference_t<const Type>>(&data);
|
||||
auto *const instance = any_cast<stl::remove_reference_t<const Type>>(&data);
|
||||
ENTT_ASSERT(instance, "Invalid instance");
|
||||
return static_cast<Type>(*instance);
|
||||
}
|
||||
@@ -561,13 +561,13 @@ template<typename Type, std::size_t Len, std::size_t Align>
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved)
|
||||
[[nodiscard]] std::remove_const_t<Type> any_cast(basic_any<Len, Align> &&data) noexcept {
|
||||
if constexpr(std::is_copy_constructible_v<stl::remove_cvref_t<Type>>) {
|
||||
if(auto *const instance = any_cast<std::remove_reference_t<Type>>(&data); instance) {
|
||||
if(auto *const instance = any_cast<stl::remove_reference_t<Type>>(&data); instance) {
|
||||
return static_cast<Type>(stl::move(*instance));
|
||||
}
|
||||
|
||||
return any_cast<Type>(data);
|
||||
} else {
|
||||
auto *const instance = any_cast<std::remove_reference_t<Type>>(&data);
|
||||
auto *const instance = any_cast<stl::remove_reference_t<Type>>(&data);
|
||||
ENTT_ASSERT(instance, "Invalid instance");
|
||||
return static_cast<Type>(stl::move(*instance));
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ inline constexpr bool is_tuple_v = is_tuple<Type>::value;
|
||||
*/
|
||||
template<typename Type>
|
||||
constexpr decltype(auto) unwrap_tuple(Type &&value) noexcept {
|
||||
if constexpr(stl::tuple_size_v<std::remove_reference_t<Type>> == 1u) {
|
||||
if constexpr(stl::tuple_size_v<stl::remove_reference_t<Type>> == 1u) {
|
||||
return std::get<0>(stl::forward<Type>(value));
|
||||
} else {
|
||||
return stl::forward<Type>(value);
|
||||
|
||||
@@ -21,7 +21,7 @@ class handle_storage_iterator final {
|
||||
template<typename>
|
||||
friend class handle_storage_iterator;
|
||||
|
||||
using underlying_type = std::remove_reference_t<typename It::value_type::second_type>;
|
||||
using underlying_type = stl::remove_reference_t<typename It::value_type::second_type>;
|
||||
using entity_type = underlying_type::entity_type;
|
||||
|
||||
public:
|
||||
|
||||
@@ -91,16 +91,16 @@ struct resource_traits<Registry, type_list<Args...>, type_list<Req...>> {
|
||||
};
|
||||
|
||||
template<typename Registry, typename... Req, typename Ret, typename... Args>
|
||||
resource_traits<Registry, type_list<std::remove_reference_t<Args>...>, type_list<Req...>> free_function_to_resource_traits(Ret (*)(Args...));
|
||||
resource_traits<Registry, type_list<stl::remove_reference_t<Args>...>, type_list<Req...>> free_function_to_resource_traits(Ret (*)(Args...));
|
||||
|
||||
template<typename Registry, typename... Req, typename Ret, typename Type, typename... Args>
|
||||
resource_traits<Registry, type_list<std::remove_reference_t<Args>...>, type_list<Req...>> constrained_function_to_resource_traits(Ret (*)(Type &, Args...));
|
||||
resource_traits<Registry, type_list<stl::remove_reference_t<Args>...>, type_list<Req...>> constrained_function_to_resource_traits(Ret (*)(Type &, Args...));
|
||||
|
||||
template<typename Registry, typename... Req, typename Ret, typename Class, typename... Args>
|
||||
resource_traits<Registry, type_list<std::remove_reference_t<Args>...>, type_list<Req...>> constrained_function_to_resource_traits(Ret (Class::*)(Args...));
|
||||
resource_traits<Registry, type_list<stl::remove_reference_t<Args>...>, type_list<Req...>> constrained_function_to_resource_traits(Ret (Class::*)(Args...));
|
||||
|
||||
template<typename Registry, typename... Req, typename Ret, typename Class, typename... Args>
|
||||
resource_traits<Registry, type_list<std::remove_reference_t<Args>...>, type_list<Req...>> constrained_function_to_resource_traits(Ret (Class::*)(Args...) const);
|
||||
resource_traits<Registry, type_list<stl::remove_reference_t<Args>...>, type_list<Req...>> constrained_function_to_resource_traits(Ret (Class::*)(Args...) const);
|
||||
|
||||
} // namespace internal
|
||||
/*! @endcond */
|
||||
@@ -142,7 +142,7 @@ class basic_organizer final {
|
||||
} else if constexpr(internal::is_group_v<Type>) {
|
||||
return static_cast<Type>(as_group{reg});
|
||||
} else {
|
||||
return reg.ctx().template emplace<std::remove_reference_t<Type>>();
|
||||
return reg.ctx().template emplace<stl::remove_reference_t<Type>>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ class registry_storage_iterator final {
|
||||
template<typename>
|
||||
friend class registry_storage_iterator;
|
||||
|
||||
using mapped_type = std::remove_reference_t<decltype(stl::declval<It>()->second)>;
|
||||
using mapped_type = stl::remove_reference_t<decltype(stl::declval<It>()->second)>;
|
||||
|
||||
public:
|
||||
using value_type = stl::pair<id_type, constness_as_t<typename mapped_type::element_type, mapped_type> &>;
|
||||
|
||||
@@ -154,7 +154,7 @@ struct basic_meta_sequence_container_traits {
|
||||
auto *const non_const = any_cast<typename Type::iterator>(&it.base());
|
||||
return {area, static_cast<Type *>(container)->insert(
|
||||
non_const ? *non_const : any_cast<const typename Type::const_iterator &>(it.base()),
|
||||
(value != nullptr) ? *static_cast<const Type::value_type *>(value) : *static_cast<const std::remove_reference_t<typename Type::const_reference> *>(cref))};
|
||||
(value != nullptr) ? *static_cast<const Type::value_type *>(value) : *static_cast<const stl::remove_reference_t<typename Type::const_reference> *>(cref))};
|
||||
} else {
|
||||
return iterator{};
|
||||
}
|
||||
|
||||
@@ -363,7 +363,7 @@ public:
|
||||
id,
|
||||
name,
|
||||
/* this is never static */
|
||||
std::is_const_v<std::remove_reference_t<data_type>> ? internal::meta_traits::is_const : internal::meta_traits::is_none,
|
||||
std::is_const_v<stl::remove_reference_t<data_type>> ? internal::meta_traits::is_const : internal::meta_traits::is_none,
|
||||
1u,
|
||||
&internal::resolve<stl::remove_cvref_t<data_type>>,
|
||||
&meta_arg<type_list<stl::remove_cvref_t<data_type>>>,
|
||||
|
||||
@@ -459,7 +459,7 @@ public:
|
||||
*/
|
||||
template<typename Type>
|
||||
[[nodiscard]] std::remove_const_t<Type> cast() const {
|
||||
auto *const instance = try_cast<std::remove_reference_t<Type>>();
|
||||
auto *const instance = try_cast<stl::remove_reference_t<Type>>();
|
||||
ENTT_ASSERT(instance, "Invalid instance");
|
||||
return static_cast<Type>(*instance);
|
||||
}
|
||||
@@ -468,7 +468,7 @@ public:
|
||||
template<typename Type>
|
||||
[[nodiscard]] std::remove_const_t<Type> cast() {
|
||||
// forces const on non-reference types to make them work also with wrappers for const references
|
||||
auto *const instance = try_cast<std::remove_reference_t<const Type>>();
|
||||
auto *const instance = try_cast<stl::remove_reference_t<const Type>>();
|
||||
ENTT_ASSERT(instance, "Invalid instance");
|
||||
return static_cast<Type>(*instance);
|
||||
}
|
||||
@@ -494,7 +494,7 @@ public:
|
||||
*/
|
||||
template<typename Type>
|
||||
[[nodiscard]] meta_any allow_cast() const {
|
||||
if constexpr(!std::is_reference_v<Type> || std::is_const_v<std::remove_reference_t<Type>>) {
|
||||
if constexpr(!std::is_reference_v<Type> || std::is_const_v<stl::remove_reference_t<Type>>) {
|
||||
if(storage.has_value<stl::remove_cvref_t<Type>>()) {
|
||||
return as_ref();
|
||||
} else if(*this) {
|
||||
@@ -530,8 +530,8 @@ public:
|
||||
*/
|
||||
template<typename Type>
|
||||
[[nodiscard]] bool allow_cast() {
|
||||
if constexpr(std::is_reference_v<Type> && !std::is_const_v<std::remove_reference_t<Type>>) {
|
||||
return allow_cast<const std::remove_reference_t<Type> &>() && (storage.policy() != any_policy::cref);
|
||||
if constexpr(std::is_reference_v<Type> && !std::is_const_v<stl::remove_reference_t<Type>>) {
|
||||
return allow_cast<const stl::remove_reference_t<Type> &>() && (storage.policy() != any_policy::cref);
|
||||
} else {
|
||||
if(storage.has_value<stl::remove_cvref_t<Type>>()) {
|
||||
return true;
|
||||
|
||||
@@ -165,7 +165,7 @@ template<typename Type, typename Value>
|
||||
|
||||
template<auto Member>
|
||||
[[nodiscard]] auto *look_for(const meta_context &context, const meta_type_node &node, const id_type id, bool recursive) {
|
||||
using value_type = std::remove_reference_t<decltype((node.details.get()->*Member))>::value_type;
|
||||
using value_type = stl::remove_reference_t<decltype((node.details.get()->*Member))>::value_type;
|
||||
|
||||
if(node.details) {
|
||||
if(auto *member = find_member((node.details.get()->*Member), id); member != nullptr) {
|
||||
|
||||
@@ -33,7 +33,7 @@ struct as_void_t final: private internal::meta_policy {
|
||||
struct as_ref_t final: private internal::meta_policy {
|
||||
/*! @cond ENTT_INTERNAL */
|
||||
template<typename Type>
|
||||
static constexpr bool value = std::is_reference_v<Type> && !std::is_const_v<std::remove_reference_t<Type>>;
|
||||
static constexpr bool value = std::is_reference_v<Type> && !std::is_const_v<stl::remove_reference_t<Type>>;
|
||||
/*! @endcond */
|
||||
};
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ struct meta_function_descriptor<Type, Ret (*)(MaybeType, Args...)>
|
||||
type_list<Args...>,
|
||||
type_list<MaybeType, Args...>>,
|
||||
!(stl::is_same_v<stl::remove_cvref_t<MaybeType>, Type> || std::is_base_of_v<stl::remove_cvref_t<MaybeType>, Type>),
|
||||
std::is_const_v<std::remove_reference_t<MaybeType>> && (stl::is_same_v<stl::remove_cvref_t<MaybeType>, Type> || std::is_base_of_v<stl::remove_cvref_t<MaybeType>, Type>)> {};
|
||||
std::is_const_v<stl::remove_reference_t<MaybeType>> && (stl::is_same_v<stl::remove_cvref_t<MaybeType>, Type> || std::is_base_of_v<stl::remove_cvref_t<MaybeType>, Type>)> {};
|
||||
|
||||
/**
|
||||
* @brief Meta function descriptor.
|
||||
@@ -169,7 +169,7 @@ template<meta_policy Policy = as_value_t, typename Type>
|
||||
[[nodiscard]] meta_any meta_dispatch(const meta_ctx &ctx, [[maybe_unused]] Type &&value) {
|
||||
if constexpr(stl::is_same_v<Policy, as_cref_t>) {
|
||||
static_assert(stl::is_lvalue_reference_v<Type>, "Invalid type");
|
||||
return meta_any{ctx, std::in_place_type<const std::remove_reference_t<Type> &>, stl::as_const(value)};
|
||||
return meta_any{ctx, std::in_place_type<const stl::remove_reference_t<Type> &>, stl::as_const(value)};
|
||||
} else if constexpr(stl::is_same_v<Policy, as_ref_t> || (stl::is_same_v<Policy, as_is_t> && stl::is_lvalue_reference_v<Type>)) {
|
||||
return meta_any{ctx, std::in_place_type<Type>, value};
|
||||
} else if constexpr(stl::is_same_v<Policy, as_void_t>) {
|
||||
@@ -206,14 +206,14 @@ template<typename Policy, typename Candidate, typename... Args>
|
||||
|
||||
template<typename Type, typename Policy, typename Candidate, std::size_t... Index>
|
||||
[[nodiscard]] meta_any meta_invoke(meta_any &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>>;
|
||||
using descriptor = meta_function_helper_t<Type, stl::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 constexpr(std::is_invocable_v<stl::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(), stl::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>...>) {
|
||||
} else if constexpr(std::is_invocable_v<stl::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(), stl::forward<Candidate>(candidate), *clazz, (args + Index)->cast<type_list_element_t<Index, typename descriptor::args_type>>()...);
|
||||
}
|
||||
@@ -275,7 +275,7 @@ template<typename Type>
|
||||
*/
|
||||
template<typename Type, auto Data>
|
||||
[[nodiscard]] bool meta_setter([[maybe_unused]] meta_handle instance, [[maybe_unused]] meta_any value) {
|
||||
if constexpr(std::is_member_function_pointer_v<decltype(Data)> || std::is_function_v<std::remove_reference_t<stl::remove_pointer_t<decltype(Data)>>>) {
|
||||
if constexpr(std::is_member_function_pointer_v<decltype(Data)> || std::is_function_v<stl::remove_reference_t<stl::remove_pointer_t<decltype(Data)>>>) {
|
||||
using descriptor = meta_function_helper_t<Type, decltype(Data)>;
|
||||
using data_type = type_list_element_t<descriptor::is_static, typename descriptor::args_type>;
|
||||
|
||||
@@ -284,7 +284,7 @@ template<typename Type, auto Data>
|
||||
return true;
|
||||
}
|
||||
} else if constexpr(stl::is_member_object_pointer_v<decltype(Data)>) {
|
||||
using data_type = std::remove_reference_t<typename meta_function_helper_t<Type, decltype(Data)>::return_type>;
|
||||
using data_type = stl::remove_reference_t<typename meta_function_helper_t<Type, decltype(Data)>::return_type>;
|
||||
|
||||
if constexpr(!std::is_array_v<data_type> && !std::is_const_v<data_type>) {
|
||||
if(auto *const clazz = instance->try_cast<Type>(); clazz && value.allow_cast<data_type>()) {
|
||||
@@ -293,7 +293,7 @@ template<typename Type, auto Data>
|
||||
}
|
||||
}
|
||||
} else if constexpr(stl::is_pointer_v<decltype(Data)>) {
|
||||
using data_type = std::remove_reference_t<decltype(*Data)>;
|
||||
using data_type = stl::remove_reference_t<decltype(*Data)>;
|
||||
|
||||
if constexpr(!std::is_array_v<data_type> && !std::is_const_v<data_type>) {
|
||||
if(value.allow_cast<data_type>()) {
|
||||
@@ -316,7 +316,7 @@ template<typename Type, auto Data>
|
||||
*/
|
||||
template<typename Type, auto Data, meta_policy Policy = as_value_t>
|
||||
[[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<stl::remove_pointer_t<decltype(Data)>>>) {
|
||||
if constexpr(std::is_member_pointer_v<decltype(Data)> || std::is_function_v<stl::remove_reference_t<stl::remove_pointer_t<decltype(Data)>>>) {
|
||||
if constexpr(!std::is_array_v<stl::remove_cvref_t<stl::invoke_result_t<decltype(Data), Type &>>>) {
|
||||
if constexpr(std::is_invocable_v<decltype(Data), Type &>) {
|
||||
if(auto *clazz = instance->try_cast<Type>(); clazz) {
|
||||
@@ -355,7 +355,7 @@ template<typename Type, auto Data, meta_policy Policy = as_value_t>
|
||||
*/
|
||||
template<typename Type, meta_policy Policy = as_value_t, typename Candidate>
|
||||
[[nodiscard]] meta_any meta_invoke(meta_handle instance, Candidate &&candidate, meta_any *const args) {
|
||||
return internal::meta_invoke<Type, Policy>(*instance.operator->(), stl::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, Policy>(*instance.operator->(), stl::forward<Candidate>(candidate), args, std::make_index_sequence<meta_function_helper_t<Type, stl::remove_reference_t<Candidate>>::args_type::size>{});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -369,7 +369,7 @@ template<typename Type, meta_policy Policy = as_value_t, typename Candidate>
|
||||
*/
|
||||
template<typename Type, auto Candidate, meta_policy Policy = as_value_t>
|
||||
[[nodiscard]] meta_any meta_invoke(meta_handle instance, meta_any *const args) {
|
||||
return internal::meta_invoke<Type, Policy>(*instance.operator->(), Candidate, args, std::make_index_sequence<meta_function_helper_t<Type, std::remove_reference_t<decltype(Candidate)>>::args_type::size>{});
|
||||
return internal::meta_invoke<Type, Policy>(*instance.operator->(), Candidate, args, std::make_index_sequence<meta_function_helper_t<Type, stl::remove_reference_t<decltype(Candidate)>>::args_type::size>{});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -421,10 +421,10 @@ template<typename Type, typename Policy = as_value_t, 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<stl::remove_cvref_t<Candidate>>) {
|
||||
meta_any placeholder{meta_ctx_arg, ctx};
|
||||
return internal::meta_invoke<Type, Policy>(placeholder, stl::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, Policy>(placeholder, stl::forward<Candidate>(candidate), args, std::make_index_sequence<meta_function_helper_t<Type, stl::remove_reference_t<Candidate>>::args_type::size>{});
|
||||
} else {
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - waiting for C++20 (and std::span)
|
||||
return internal::meta_invoke<Type, Policy>(*args, stl::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, Policy>(*args, stl::forward<Candidate>(candidate), args + 1u, std::make_index_sequence<meta_function_helper_t<Type, stl::remove_reference_t<Candidate>>::args_type::size>{});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ using std::is_same_v;
|
||||
using std::is_void_v;
|
||||
using std::remove_cvref_t;
|
||||
using std::remove_pointer_t;
|
||||
using std::remove_reference_t;
|
||||
using std::true_type;
|
||||
|
||||
} // namespace entt::stl
|
||||
|
||||
Reference in New Issue
Block a user