13 static constexpr bool value = std::is_default_constructible<actual_type_t<T>>::value;
18template <
typename T,
bool Destroy>
20 constexpr bool trivial = Destroy ? is_trivially_destructible_v<T> : is_trivially_constructible_v<T>;
21 constexpr bool legal = Destroy ? is_destructible_v<T> : is_default_constructible_v<T>;
22 if constexpr (trivial) {
24 }
else if constexpr (!legal) {
25 flecs_static_assert(!Destroy || always_false<T>::value,
"component type must be destructible");
26 flags |= Destroy ? ECS_TYPE_HOOK_DTOR_ILLEGAL : ECS_TYPE_HOOK_CTOR_ILLEGAL;
32 T *arr =
static_cast<T*
>(ptr);
33 for (int32_t i = 0; i < count; i ++) {
34 if constexpr (Destroy) {
37 FLECS_PLACEMENT_NEW(&arr[i], T);
44template <
typename T,
bool Move,
bool Construct,
bool Destroy = false>
45conditional_t<Move, ecs_move_t, ecs_copy_t> transfer(ecs_flags32_t& flags) {
46 constexpr bool trivial = (Construct
47 ? (Move ? is_trivially_move_constructible_v<T> : is_trivially_copy_constructible_v<T>)
48 : (Move ? is_trivially_move_assignable_v<T> : is_trivially_copyable_v<T>)) &&
49 (!Destroy || is_trivially_destructible_v<T>);
50 constexpr bool legal = (Construct
51 ? (Move ? is_move_constructible_v<T> : is_copy_constructible_v<T>)
52 : (Move ? is_move_assignable_v<T> : is_copy_assignable_v<T>)) &&
53 (!Destroy || is_destructible_v<T>);
54 constexpr auto illegal = Move
56 ? (Destroy ? ECS_TYPE_HOOK_CTOR_MOVE_DTOR_ILLEGAL : ECS_TYPE_HOOK_MOVE_CTOR_ILLEGAL)
57 : (Destroy ? ECS_TYPE_HOOK_MOVE_DTOR_ILLEGAL : ECS_TYPE_HOOK_MOVE_ILLEGAL))
58 : (Construct ? ECS_TYPE_HOOK_COPY_CTOR_ILLEGAL : ECS_TYPE_HOOK_COPY_ILLEGAL);
59 if constexpr (trivial) {
61 }
else if constexpr (!legal) {
65 return [](
void *dst_ptr, conditional_t<Move, void*, const void*> src_ptr,
70 T *dst =
static_cast<T*
>(dst_ptr);
71 auto src =
static_cast<conditional_t<Move, T*, const T*>
>(src_ptr);
72 for (int32_t i = 0; i < count; i ++) {
73 using Value = conditional_t<Move, T&&, const T&>;
74 if constexpr (Destroy && !Construct && is_trivially_move_assignable_v<T>) {
77 if constexpr (Construct) {
78 FLECS_PLACEMENT_NEW(&dst[i], T(
static_cast<Value
>(src[i])));
80 dst[i] =
static_cast<Value
>(src[i]);
82 if constexpr (Destroy && (Construct || !is_trivially_move_assignable_v<T>)) {
97 #pragma clang diagnostic push
98 #pragma clang diagnostic ignored "-Wfloat-equal"
99#elif defined(__GNUC__) && !defined(__clang__)
100 #pragma GCC diagnostic push
101 #pragma GCC diagnostic ignored "-Wfloat-equal"
105template <
typename T,
typename =
void>
110struct has_operator_less<T, void_t<decltype(std::declval<const T&>() < std::declval<const T&>())>> :
111 std::is_same<decltype(std::declval<const T&>() < std::declval<const T&>()), bool> {};
114template <typename T, typename = void>
115struct has_operator_greater : std::false_type {};
119struct has_operator_greater<T, void_t<decltype(std::declval<const T&>() > std::declval<const T&>())>> :
120 std::is_same<decltype(std::declval<const T&>() > std::declval<const T&>()), bool> {};
123template <
typename T,
typename =
void>
128struct has_operator_equal<T, void_t<decltype(std::declval<const T&>() == std::declval<const T&>())>> :
129 std::is_same<decltype(std::declval<const T&>() == std::declval<const T&>()), bool> {};
133int compare_impl(
const void *a,
const void *b,
const ecs_type_info_t *) {
134 const T& lhs = *
static_cast<const T*
>(a);
135 const T& rhs = *
static_cast<const T*
>(b);
139 if (lhs == rhs)
return 0;
140 if (lhs < rhs)
return -1;
142 }
else if constexpr (has_operator_greater<T>::value && has_operator_equal<T>::value) {
144 if (lhs == rhs)
return 0;
145 if (lhs > rhs)
return 1;
147 }
else if constexpr (has_operator_less<T>::value && has_operator_greater<T>::value) {
149 if (lhs < rhs)
return -1;
150 if (lhs > rhs)
return 1;
154 if (lhs < rhs)
return -1;
155 if (rhs < lhs)
return 1;
159 if (lhs > rhs)
return 1;
160 if (rhs > lhs)
return -1;
173 return compare_impl<T>;
181bool equals_impl(
const void *a,
const void *b,
const ecs_type_info_t *) {
182 const T& lhs = *
static_cast<const T*
>(a);
183 const T& rhs = *
static_cast<const T*
>(b);
190 return equals_impl<T>;
197#if defined(__clang__)
198 #pragma clang diagnostic pop
199#elif defined(__GNUC__) && !defined(__clang__)
200 #pragma GCC diagnostic pop
#define ecs_assert(condition, error_code,...)
Assert.
#define ECS_INTERNAL_ERROR
Internal error code.
struct ecs_type_info_t ecs_type_info_t
Type information.
void(*) ecs_xtor_t(void *ptr, int32_t count, const ecs_type_info_t *type_info)
Constructor/destructor callback.
bool(*) ecs_equals_t(const void *a_ptr, const void *b_ptr, const ecs_type_info_t *type_info)
Equals operator hook.
int(*) ecs_cmp_t(const void *a_ptr, const void *b_ptr, const ecs_type_info_t *type_info)
Compare hook to compare component instances.
Type that contains component information (passed to ctors/dtors/...).