[meta] Use std::is_trivially_... instead of internal copies

This commit is contained in:
Behdad Esfahbod 2021-11-02 00:04:18 -06:00
parent 30c05e8b55
commit be42800fc6
3 changed files with 7 additions and 77 deletions

View File

@ -29,6 +29,8 @@
#include "hb.hh" #include "hb.hh"
#include <type_traits>
/* /*
* C++ template meta-programming & fundamentals used with them. * C++ template meta-programming & fundamentals used with them.
@ -355,62 +357,6 @@ using hb_is_move_assignable = hb_is_assignable<hb_add_lvalue_reference<T>,
hb_add_rvalue_reference<T>>; hb_add_rvalue_reference<T>>;
#define hb_is_move_assignable(T) hb_is_move_assignable<T>::value #define hb_is_move_assignable(T) hb_is_move_assignable<T>::value
/* Trivial versions. */
template <typename T> union hb_trivial { T value; };
template <typename T>
using hb_is_trivially_destructible= hb_is_destructible<hb_trivial<T>>;
#define hb_is_trivially_destructible(T) hb_is_trivially_destructible<T>::value
/* Don't know how to do the following. */
//template <typename T, typename ...Ts>
//using hb_is_trivially_constructible= hb_is_constructible<hb_trivial<T>, hb_trivial<Ts>...>;
//#define hb_is_trivially_constructible(...) hb_is_trivially_constructible<__VA_ARGS__>::value
template <typename T>
using hb_is_trivially_default_constructible= hb_is_default_constructible<hb_trivial<T>>;
#define hb_is_trivially_default_constructible(T) hb_is_trivially_default_constructible<T>::value
template <typename T>
using hb_is_trivially_copy_constructible= hb_is_copy_constructible<hb_trivial<T>>;
#define hb_is_trivially_copy_constructible(T) hb_is_trivially_copy_constructible<T>::value
template <typename T>
using hb_is_trivially_move_constructible= hb_is_move_constructible<hb_trivial<T>>;
#define hb_is_trivially_move_constructible(T) hb_is_trivially_move_constructible<T>::value
/* Don't know how to do the following. */
//template <typename T, typename U>
//using hb_is_trivially_assignable= hb_is_assignable<hb_trivial<T>, hb_trivial<U>>;
//#define hb_is_trivially_assignable(T,U) hb_is_trivially_assignable<T, U>::value
template <typename T>
using hb_is_trivially_copy_assignable= hb_is_copy_assignable<hb_trivial<T>>;
#define hb_is_trivially_copy_assignable(T) hb_is_trivially_copy_assignable<T>::value
template <typename T>
using hb_is_trivially_move_assignable= hb_is_move_assignable<hb_trivial<T>>;
#define hb_is_trivially_move_assignable(T) hb_is_trivially_move_assignable<T>::value
template <typename T>
using hb_is_trivially_copyable= hb_bool_constant<
hb_is_trivially_destructible (T) &&
(!hb_is_move_assignable (T) || hb_is_trivially_move_assignable (T)) &&
(!hb_is_move_constructible (T) || hb_is_trivially_move_constructible (T)) &&
(!hb_is_copy_assignable (T) || hb_is_trivially_copy_assignable (T)) &&
(!hb_is_copy_constructible (T) || hb_is_trivially_copy_constructible (T)) &&
true
>;
#define hb_is_trivially_copyable(T) hb_is_trivially_copyable<T>::value
template <typename T>
using hb_is_trivial= hb_bool_constant<
hb_is_trivially_copyable (T) &&
hb_is_trivially_default_constructible (T)
>;
#define hb_is_trivial(T) hb_is_trivial<T>::value
/* hb_unwrap_type (T) /* hb_unwrap_type (T)
* If T has no T::type, returns T. Otherwise calls itself on T::type recursively. * If T has no T::type, returns T. Otherwise calls itself on T::type recursively.
*/ */

View File

@ -518,7 +518,7 @@ struct UnsizedArrayOf
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
if (unlikely (!sanitize_shallow (c, count))) return_trace (false); if (unlikely (!sanitize_shallow (c, count))) return_trace (false);
if (!sizeof... (Ts) && hb_is_trivially_copyable (Type)) return_trace (true); if (!sizeof... (Ts) && std::is_trivially_copyable<Type>::value) return_trace (true);
for (unsigned int i = 0; i < count; i++) for (unsigned int i = 0; i < count; i++)
if (unlikely (!c->dispatch (arrayZ[i], hb_forward<Ts> (ds)...))) if (unlikely (!c->dispatch (arrayZ[i], hb_forward<Ts> (ds)...)))
return_trace (false); return_trace (false);
@ -707,7 +707,7 @@ struct ArrayOf
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
if (unlikely (!sanitize_shallow (c))) return_trace (false); if (unlikely (!sanitize_shallow (c))) return_trace (false);
if (!sizeof... (Ts) && hb_is_trivially_copyable (Type)) return_trace (true); if (!sizeof... (Ts) && std::is_trivially_copyable<Type>::value) return_trace (true);
unsigned int count = len; unsigned int count = len;
for (unsigned int i = 0; i < count; i++) for (unsigned int i = 0; i < count; i++)
if (unlikely (!c->dispatch (arrayZ[i], hb_forward<Ts> (ds)...))) if (unlikely (!c->dispatch (arrayZ[i], hb_forward<Ts> (ds)...)))
@ -835,7 +835,7 @@ struct HeadlessArrayOf
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
if (unlikely (!sanitize_shallow (c))) return_trace (false); if (unlikely (!sanitize_shallow (c))) return_trace (false);
if (!sizeof... (Ts) && hb_is_trivially_copyable (Type)) return_trace (true); if (!sizeof... (Ts) && std::is_trivially_copyable<Type>::value) return_trace (true);
unsigned int count = get_length (); unsigned int count = get_length ();
for (unsigned int i = 0; i < count; i++) for (unsigned int i = 0; i < count; i++)
if (unlikely (!c->dispatch (arrayZ[i], hb_forward<Ts> (ds)...))) if (unlikely (!c->dispatch (arrayZ[i], hb_forward<Ts> (ds)...)))
@ -884,7 +884,7 @@ struct ArrayOfM1
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
if (unlikely (!sanitize_shallow (c))) return_trace (false); if (unlikely (!sanitize_shallow (c))) return_trace (false);
if (!sizeof... (Ts) && hb_is_trivially_copyable (Type)) return_trace (true); if (!sizeof... (Ts) && std::is_trivially_copyable<Type>::value) return_trace (true);
unsigned int count = lenM1 + 1; unsigned int count = lenM1 + 1;
for (unsigned int i = 0; i < count; i++) for (unsigned int i = 0; i < count; i++)
if (unlikely (!c->dispatch (arrayZ[i], hb_forward<Ts> (ds)...))) if (unlikely (!c->dispatch (arrayZ[i], hb_forward<Ts> (ds)...)))
@ -1070,7 +1070,7 @@ struct VarSizedBinSearchArrayOf
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
if (unlikely (!sanitize_shallow (c))) return_trace (false); if (unlikely (!sanitize_shallow (c))) return_trace (false);
if (!sizeof... (Ts) && hb_is_trivially_copyable (Type)) return_trace (true); if (!sizeof... (Ts) && std::is_trivially_copyable<Type>::value) return_trace (true);
unsigned int count = get_length (); unsigned int count = get_length ();
for (unsigned int i = 0; i < count; i++) for (unsigned int i = 0; i < count; i++)
if (unlikely (!(*this)[i].sanitize (c, hb_forward<Ts> (ds)...))) if (unlikely (!(*this)[i].sanitize (c, hb_forward<Ts> (ds)...)))

View File

@ -108,22 +108,6 @@ main (int argc, char **argv)
static_assert (hb_is_constructible (X, Y), ""); static_assert (hb_is_constructible (X, Y), "");
static_assert (!hb_is_constructible (Y, X), ""); static_assert (!hb_is_constructible (Y, X), "");
static_assert (hb_is_trivially_default_constructible (X), "");
static_assert (hb_is_trivially_default_constructible (Y), "");
static_assert (hb_is_trivially_copy_constructible (X), "");
static_assert (hb_is_trivially_copy_constructible (Y), "");
static_assert (hb_is_trivially_move_constructible (X), "");
static_assert (hb_is_trivially_move_constructible (Y), "");
static_assert (hb_is_trivially_destructible (Y), "");
static_assert (hb_is_trivially_copyable (int), "");
static_assert (hb_is_trivially_copyable (X), "");
static_assert (hb_is_trivially_copyable (Y), "");
static_assert (hb_is_trivial (int), "");
static_assert (hb_is_trivial (X), "");
static_assert (hb_is_trivial (Y), "");
static_assert (hb_is_signed (hb_unwrap_type (U<U<U<int>>>)), ""); static_assert (hb_is_signed (hb_unwrap_type (U<U<U<int>>>)), "");
static_assert (hb_is_unsigned (hb_unwrap_type (U<U<U<U<unsigned>>>>)), ""); static_assert (hb_is_unsigned (hb_unwrap_type (U<U<U<U<unsigned>>>>)), "");