component: yet another piece to fully support non-movable types (see #905)
This commit is contained in:
@@ -14,8 +14,8 @@ namespace entt {
|
||||
|
||||
namespace internal {
|
||||
|
||||
template<typename, typename = void>
|
||||
struct in_place_delete: std::false_type {};
|
||||
template<typename Type, typename = void>
|
||||
struct in_place_delete: std::bool_constant<!(std::is_move_constructible_v<Type> && std::is_move_assignable_v<Type>)> {};
|
||||
|
||||
template<typename Type>
|
||||
struct in_place_delete<Type, std::enable_if_t<Type::in_place_delete>>
|
||||
|
||||
@@ -1,6 +1,19 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <entt/entity/component.hpp>
|
||||
|
||||
struct empty {};
|
||||
|
||||
struct non_empty {
|
||||
int value;
|
||||
};
|
||||
|
||||
struct non_movable {
|
||||
non_movable() = default;
|
||||
non_movable(const non_movable &) = delete;
|
||||
non_movable &operator=(const non_movable &) = delete;
|
||||
int value;
|
||||
};
|
||||
|
||||
struct self_contained {
|
||||
static constexpr auto in_place_delete = true;
|
||||
static constexpr auto page_size = 4u;
|
||||
@@ -15,36 +28,39 @@ struct entt::component_traits<traits_based> {
|
||||
static constexpr auto page_size = 8u;
|
||||
};
|
||||
|
||||
struct default_params_empty {};
|
||||
struct default_params_non_empty {
|
||||
int value;
|
||||
};
|
||||
|
||||
TEST(Component, VoidType) {
|
||||
using traits = entt::component_traits<void>;
|
||||
|
||||
static_assert(!traits::in_place_delete);
|
||||
static_assert(traits::in_place_delete);
|
||||
static_assert(entt::ignore_as_empty_v<typename traits::type>);
|
||||
// we don't really care about this thanks to ignore_as_empty_v
|
||||
static_assert(traits::page_size != 0u);
|
||||
}
|
||||
|
||||
TEST(Component, DefaultParamsEmpty) {
|
||||
using traits = entt::component_traits<default_params_empty>;
|
||||
TEST(Component, Empty) {
|
||||
using traits = entt::component_traits<empty>;
|
||||
|
||||
static_assert(!traits::in_place_delete);
|
||||
static_assert(entt::ignore_as_empty_v<typename traits::type>);
|
||||
static_assert(traits::page_size == 0u);
|
||||
}
|
||||
|
||||
TEST(Component, DefaultParamsNonEmpty) {
|
||||
using traits = entt::component_traits<default_params_non_empty>;
|
||||
TEST(Component, NonEmpty) {
|
||||
using traits = entt::component_traits<non_empty>;
|
||||
|
||||
static_assert(!traits::in_place_delete);
|
||||
static_assert(!entt::ignore_as_empty_v<typename traits::type>);
|
||||
static_assert(traits::page_size == ENTT_PACKED_PAGE);
|
||||
}
|
||||
|
||||
TEST(Component, NonMovable) {
|
||||
using traits = entt::component_traits<non_movable>;
|
||||
|
||||
static_assert(traits::in_place_delete);
|
||||
static_assert(!entt::ignore_as_empty_v<typename traits::type>);
|
||||
static_assert(traits::page_size == ENTT_PACKED_PAGE);
|
||||
}
|
||||
|
||||
TEST(Component, SelfContained) {
|
||||
using traits = entt::component_traits<self_contained>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user