*: minor changes
This commit is contained in:
@@ -72,7 +72,7 @@ class any {
|
||||
case operation::CADDR:
|
||||
return instance;
|
||||
case operation::REF:
|
||||
as_any(to).vtable = basic_vtable<std::add_lvalue_reference_t<Type>>;
|
||||
as_any(to).vtable = basic_vtable<Type &>;
|
||||
as_any(to).instance = instance;
|
||||
break;
|
||||
case operation::TYPE:
|
||||
@@ -94,7 +94,7 @@ class any {
|
||||
case operation::CADDR:
|
||||
return from.instance;
|
||||
case operation::REF:
|
||||
as_any(to).vtable = basic_vtable<std::add_lvalue_reference_t<Type>>;
|
||||
as_any(to).vtable = basic_vtable<Type &>;
|
||||
as_any(to).instance = from.instance;
|
||||
break;
|
||||
case operation::TYPE:
|
||||
@@ -140,7 +140,7 @@ public:
|
||||
*/
|
||||
template<typename Type>
|
||||
any(std::reference_wrapper<Type> value) ENTT_NOEXCEPT
|
||||
: vtable{&basic_vtable<std::add_lvalue_reference_t<Type>>},
|
||||
: vtable{&basic_vtable<Type &>},
|
||||
instance{&value.get()}
|
||||
{}
|
||||
|
||||
@@ -279,6 +279,7 @@ Type any_cast(const any &data) ENTT_NOEXCEPT {
|
||||
/*! @copydoc any_cast */
|
||||
template<typename Type>
|
||||
Type any_cast(any &data) ENTT_NOEXCEPT {
|
||||
// forces const on non-reference types to make them work also with wrappers for const references
|
||||
auto * const instance = any_cast<std::conditional_t<std::is_reference_v<Type>, std::remove_reference_t<Type>, const Type>>(&data);
|
||||
ENTT_ASSERT(instance);
|
||||
return static_cast<Type>(*instance);
|
||||
@@ -288,6 +289,7 @@ Type any_cast(any &data) ENTT_NOEXCEPT {
|
||||
/*! @copydoc any_cast */
|
||||
template<typename Type>
|
||||
Type any_cast(any &&data) ENTT_NOEXCEPT {
|
||||
// forces const on non-reference types to make them work also with wrappers for const references
|
||||
auto * const instance = any_cast<std::conditional_t<std::is_reference_v<Type>, std::remove_reference_t<Type>, const Type>>(&data);
|
||||
ENTT_ASSERT(instance);
|
||||
return static_cast<Type>(std::move(*instance));
|
||||
@@ -304,12 +306,8 @@ const Type * any_cast(const any *data) ENTT_NOEXCEPT {
|
||||
/*! @copydoc any_cast */
|
||||
template<typename Type>
|
||||
Type * any_cast(any *data) ENTT_NOEXCEPT {
|
||||
if constexpr(std::is_const_v<Type>) {
|
||||
// last attempt to make wrappers for const references return their values
|
||||
return any_cast<std::remove_const_t<Type>>(&std::as_const(*data));
|
||||
} else {
|
||||
return (data->type() == type_id<Type>() ? static_cast<Type *>(data->data()) : nullptr);
|
||||
}
|
||||
// last attempt to make wrappers for const references return their values
|
||||
return (data->type() == type_id<Type>() ? static_cast<Type *>(static_cast<constness_as_t<any, Type> *>(data)->data()) : nullptr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -48,17 +48,17 @@ class basic_snapshot {
|
||||
}
|
||||
}
|
||||
|
||||
template<typename... Component, typename Archive, typename It, std::size_t... Indexes>
|
||||
void component(Archive &archive, It first, It last, std::index_sequence<Indexes...>) const {
|
||||
std::array<std::size_t, sizeof...(Indexes)> size{};
|
||||
template<typename... Component, typename Archive, typename It, std::size_t... Index>
|
||||
void component(Archive &archive, It first, It last, std::index_sequence<Index...>) const {
|
||||
std::array<std::size_t, sizeof...(Index)> size{};
|
||||
auto begin = first;
|
||||
|
||||
while(begin != last) {
|
||||
const auto entt = *(begin++);
|
||||
((reg->template has<Component>(entt) ? ++size[Indexes] : size[Indexes]), ...);
|
||||
((reg->template has<Component>(entt) ? ++size[Index] : size[Index]), ...);
|
||||
}
|
||||
|
||||
(get<Component>(archive, size[Indexes], first, last), ...);
|
||||
(get<Component>(archive, size[Index], first, last), ...);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
@@ -305,9 +305,9 @@ public:
|
||||
if constexpr(sizeof...(Comp) == 0) {
|
||||
return component;
|
||||
} else if constexpr(sizeof...(Comp) == 1) {
|
||||
return (std::get<std::add_lvalue_reference_t<Comp>>(component), ...);
|
||||
return (std::get<Comp &>(component), ...);
|
||||
} else {
|
||||
return std::forward_as_tuple(std::get<std::add_lvalue_reference_t<Comp>>(component)...);
|
||||
return std::forward_as_tuple(std::get<Comp &>(component)...);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -261,8 +261,8 @@ public:
|
||||
return extent(dim, std::make_index_sequence<std::rank_v<Type>>{});
|
||||
},
|
||||
&compare, // workaround for an issue with VS2017
|
||||
&meta_node<std::remove_const_t<std::remove_pointer_t<Type>>>::resolve,
|
||||
&meta_node<std::remove_const_t<std::remove_extent_t<Type>>>::resolve
|
||||
&meta_node<std::remove_cv_t<std::remove_pointer_t<Type>>>::resolve,
|
||||
&meta_node<std::remove_cv_t<std::remove_extent_t<Type>>>::resolve
|
||||
};
|
||||
|
||||
return &node;
|
||||
|
||||
Reference in New Issue
Block a user