Skip to content

Commit

Permalink
Updated type traits generator
Browse files Browse the repository at this point in the history
  • Loading branch information
John Wellbelove committed Aug 5, 2021
1 parent 629e864 commit c265e82
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 74 deletions.
139 changes: 102 additions & 37 deletions include/etl/generators/type_traits_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,10 @@ namespace etl
template <> struct make_signed<wchar_t>
{
typedef etl::conditional<sizeof(wchar_t) == sizeof(int16_t),
int16_t,
etl::conditional<sizeof(wchar_t) == sizeof(int32_t),
int32_t,
void>::type>::type type;
int16_t,
etl::conditional<sizeof(wchar_t) == sizeof(int32_t),
int32_t,
void>::type>::type type;
};

template <> struct make_signed<unsigned short> { typedef short type; };
Expand All @@ -500,10 +500,10 @@ namespace etl
template <> struct make_unsigned<wchar_t>
{
typedef etl::conditional<sizeof(wchar_t) == sizeof(uint16_t),
uint16_t,
etl::conditional<sizeof(wchar_t) == sizeof(uint32_t),
uint32_t,
void>::type>::type type;
uint16_t,
etl::conditional<sizeof(wchar_t) == sizeof(uint32_t),
uint32_t,
void>::type>::type type;
};

template <> struct make_unsigned<int> { typedef unsigned int type; };
Expand Down Expand Up @@ -1211,6 +1211,7 @@ namespace etl
///\ingroup type_traits
template <typename T> struct alignment_of : std::alignment_of<T> {};
template <> struct alignment_of<void> : std::integral_constant<size_t, 0> {};
template <> struct alignment_of<const void> : std::integral_constant <size_t, 0> {};

#if ETL_CPP17_SUPPORTED
template <typename T>
Expand Down Expand Up @@ -1565,7 +1566,7 @@ namespace etl
struct is_trivially_constructible<T, false>;
#endif

//***************************************************************************
//*********************************************
// is_trivially_copy_constructible
#if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED
template <typename T>
Expand All @@ -1585,7 +1586,7 @@ namespace etl
struct is_trivially_copy_constructible<T, false>;
#endif

//***************************************************************************
//*********************************************
// is_trivially_destructible
#if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED
template <typename T>
Expand All @@ -1605,7 +1606,7 @@ namespace etl
struct is_trivially_destructible<T, false>;
#endif

//***************************************************************************
//*********************************************
// is_trivially_copy_assignable
#if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED
template <typename T>
Expand All @@ -1625,7 +1626,7 @@ namespace etl
struct is_trivially_copy_assignable<T, false>;
#endif

//***************************************************************************
//*********************************************
// is_trivially_copyable
#if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED
template <typename T>
Expand All @@ -1645,7 +1646,7 @@ namespace etl
struct is_trivially_copyable<T, false>;
#endif

#elif defined(ETL_USE_TYPE_TRAITS_BUILTINS)
#elif defined(ETL_USE_TYPE_TRAITS_BUILTINS) && !defined(ETL_USER_DEFINED_TYPE_TRAITS)

//*********************************************
// Use the compiler's builtins.
Expand All @@ -1654,23 +1655,41 @@ namespace etl
//*********************************************
// is_assignable
template<typename T1, typename T2>
struct is_assignable : public etl::bool_constant<__is_assignable(T1, T2)>
struct is_assignable
{
static ETL_CONSTANT bool value = __is_assignable(T1, T2);
};

#if ETL_CPP11_SUPPORTED
//*********************************************
// is_constructible
template<typename T, typename... TArgs>
struct is_constructible : public etl::bool_constant<__is_constructible(T, TArgs...)>
struct is_constructible
{
static ETL_CONSTANT bool value = __is_constructible(T, TArgs...);
};
#else
//*********************************************
// is_constructible
template<typename T, typename TArgs = void>
struct is_constructible
{
static ETL_CONSTANT bool value = __is_constructible(T, TArgs);
};

//*********************************************
// is_constructible
template<typename T>
struct is_constructible<T, void>
{
static ETL_CONSTANT bool value = __is_constructible(T);
};
#endif

//*********************************************
// is_copy_constructible
template <typename T>
struct is_copy_constructible : public etl::is_constructible<T, etl::add_lvalue_reference_t<const T>>
struct is_copy_constructible : public etl::is_constructible<T, typename etl::add_lvalue_reference<const T>::type>
{
};

Expand All @@ -1681,42 +1700,88 @@ namespace etl
{
};

#if ETL_CPP11_SUPPORTED
//*********************************************
// is_trivially_constructible
template <typename T, typename... TArgs>
struct is_trivially_constructible
{
#if defined(ETL_COMPILER_GCC)
static ETL_CONSTANT bool value = __has_trivial_constructor(T);
#else
static ETL_CONSTANT bool value = __is_trivially_constructible(T, TArgs...);
#endif
};
#else
//*********************************************
// is_trivially_constructible
template <typename T, typename TArgs = void>
struct is_trivially_constructible
{
#if defined(ETL_COMPILER_GCC)
static ETL_CONSTANT bool value = __has_trivial_constructor(T);
#else
static ETL_CONSTANT bool value = __is_trivially_constructible(T, TArgs);
#endif
};

//*********************************************
// is_trivially_constructible
template <typename T>
struct is_trivially_constructible : public etl::bool_constant<__is_trivially_constructible(T)>
struct is_trivially_constructible<T, void>
{
#if defined(ETL_COMPILER_GCC)
static ETL_CONSTANT bool value = __has_trivial_constructor(T);
#else
static ETL_CONSTANT bool value = __is_trivially_constructible(T);
#endif
};
#endif

//***************************************************************************
//*********************************************
// is_trivially_copy_constructible
template <typename T>
struct is_trivially_copy_constructible : public etl::bool_constant<__is_trivially_copyable(T)>
struct is_trivially_copy_constructible : public is_trivially_constructible<T, typename add_lvalue_reference<const T>::type>
{
};

//***************************************************************************
//*********************************************
// is_trivially_destructible
template <typename T>
struct is_trivially_destructible : public etl::bool_constant<__is_trivially_destructible(T)>
struct is_trivially_destructible
{
#if defined(ETL_COMPILER_GCC)
static ETL_CONSTANT bool value = __has_trivial_destructor(T);
#else
static ETL_CONSTANT bool value = __is_trivially_destructible(T);
#endif
};

//***************************************************************************
//*********************************************
// is_trivially_copy_assignable
template <typename T>
struct is_trivially_copy_assignable : public etl::bool_constant<__is_trivially_copyable(T)>
struct is_trivially_copy_assignable
{
#if defined(ETL_COMPILER_GCC)
static ETL_CONSTANT bool value = __has_trivial_copy(T);
#else
static ETL_CONSTANT bool value = __is_trivially_copyable(T);
#endif
};

//***************************************************************************
//*********************************************
// is_trivially_copyable
template <typename T>
struct is_trivially_copyable : public etl::bool_constant<__is_trivially_copyable(T)>
struct is_trivially_copyable
{
#if defined(ETL_COMPILER_GCC)
static ETL_CONSTANT bool value = __has_trivial_copy(T);
#else
static ETL_CONSTANT bool value = __is_trivially_copyable(T);
#endif
};

#elif defined(ETL_USER_DEFINED_TYPE_TRAITS)
#elif defined(ETL_USER_DEFINED_TYPE_TRAITS) && !defined(ETL_USE_TYPE_TRAITS_BUILTINS)

//*********************************************
// Force the user to provide specialisations for
Expand All @@ -1726,9 +1791,9 @@ namespace etl
//*********************************************
// is_assignable
template <typename T1,
typename T2,
bool B = (etl::is_arithmetic<T1>::value || etl::is_pointer<T1>::value) && (etl::is_arithmetic<T2>::value || etl::is_pointer<T2>::value)>
struct is_assignable;
typename T2,
bool B = (etl::is_arithmetic<T1>::value || etl::is_pointer<T1>::value) && (etl::is_arithmetic<T2>::value || etl::is_pointer<T2>::value)>
struct is_assignable;

template <typename T1, typename T2>
struct is_assignable<T1, T2, true> : public etl::true_type
Expand Down Expand Up @@ -1797,7 +1862,7 @@ namespace etl
template <typename T>
struct is_trivially_constructible<T, false>;

//***************************************************************************
//*********************************************
// is_trivially_copy_constructible
template <typename T, bool B = etl::is_arithmetic<T>::value || etl::is_pointer<T>::value>
struct is_trivially_copy_constructible;
Expand All @@ -1810,7 +1875,7 @@ namespace etl
template <typename T>
struct is_trivially_copy_constructible<T, false>;

//***************************************************************************
//*********************************************
// is_trivially_destructible
template <typename T, bool B = etl::is_arithmetic<T>::value || etl::is_pointer<T>::value>
struct is_trivially_destructible;
Expand All @@ -1823,7 +1888,7 @@ namespace etl
template <typename T>
struct is_trivially_destructible<T, false>;

//***************************************************************************
//*********************************************
// is_trivially_copy_assignable
template <typename T, bool B = etl::is_arithmetic<T>::value || etl::is_pointer<T>::value>
struct is_trivially_copy_assignable;
Expand All @@ -1836,7 +1901,7 @@ namespace etl
template <typename T>
struct is_trivially_copy_assignable<T, false>;

//***************************************************************************
//*********************************************
// is_trivially_copyable
template <typename T, bool B = etl::is_arithmetic<T>::value || etl::is_pointer<T>::value>
struct is_trivially_copyable;
Expand Down Expand Up @@ -1893,28 +1958,28 @@ namespace etl
{
};

//***************************************************************************
//*********************************************
// is_trivially_copy_constructible
template <typename T>
struct is_trivially_copy_constructible : public etl::bool_constant<etl::is_arithmetic<T>::value || etl::is_pointer<T>::value>
{
};

//***************************************************************************
//*********************************************
// is_trivially_destructible
template <typename T>
struct is_trivially_destructible : public etl::bool_constant<etl::is_arithmetic<T>::value || etl::is_pointer<T>::value>
{
};

//***************************************************************************
//*********************************************
// is_trivially_copy_assignable
template <typename T>
struct is_trivially_copy_assignable : public etl::bool_constant<etl::is_arithmetic<T>::value || etl::is_pointer<T>::value>
{
};

//***************************************************************************
//*********************************************
// is_trivially_copyable
template <typename T>
struct is_trivially_copyable : public etl::bool_constant<etl::is_arithmetic<T>::value || etl::is_pointer<T>::value>
Expand Down
Loading

0 comments on commit c265e82

Please sign in to comment.