Skip to content

Commit

Permalink
improve is_constructible, is_copy_constructible, is_move_constructibl…
Browse files Browse the repository at this point in the history
…e for type traits with default definitions
  • Loading branch information
aBraM-aBraM committed Dec 20, 2022
1 parent e0b2ef5 commit 682606f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
35 changes: 23 additions & 12 deletions include/etl/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -1980,28 +1980,39 @@ namespace etl
{
};

//***************************************************************************
/// is_convertible
namespace private_type_traits
{
template <class, class T, class... Args>
struct is_constructible_ : etl::false_type {};

template <class T, class... Args>
struct is_constructible_<void_t<decltype(T(etl::declval<Args>()...))>, T, Args...> : etl::true_type {};
};

#if ETL_USING_CPP11
//*********************************************
// is_constructible
template <typename T, typename... TArgs>
struct is_constructible : public etl::bool_constant<etl::is_arithmetic<T>::value || etl::is_pointer<T>::value>
{
};
template <class T, class... Args>
using is_constructible = private_type_traits::is_constructible_<void_t<>, T, Args...>;
#endif

//*********************************************
// is_copy_constructible
template <typename T>
struct is_copy_constructible : public etl::bool_constant<etl::is_arithmetic<T>::value || etl::is_pointer<T>::value>
{
};
template <class T> struct is_copy_constructible : public is_constructible<T, typename etl::add_lvalue_reference<typename etl::add_const<T>::type>::type>{};
template <> struct is_copy_constructible<void> : public false_type{};
template <> struct is_copy_constructible<void const> : public false_type{};
template <> struct is_copy_constructible<void volatile> : public false_type{};
template <> struct is_copy_constructible<void const volatile> : public false_type{};

//*********************************************
// is_move_constructible
template <typename T>
struct is_move_constructible : public etl::bool_constant<etl::is_arithmetic<T>::value || etl::is_pointer<T>::value>
{
};
template <typename T> struct is_move_constructible: public is_constructible<T, typename etl::add_rvalue_reference<T>::type>{};
template <> struct is_move_constructible<void> : public false_type{};
template <> struct is_move_constructible<void const> : public false_type{};
template <> struct is_move_constructible<void volatile> : public false_type{};
template <> struct is_move_constructible<void const volatile> : public false_type{};

//*********************************************
// is_trivially_constructible
Expand Down
15 changes: 0 additions & 15 deletions test/test_type_traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ struct etl::is_assignable<Copyable, Copyable> : public etl::true_type
{
};

template <>
struct etl::is_constructible<Copyable> : public etl::true_type
{
};

template <>
struct etl::is_copy_constructible<Copyable> : public etl::true_type
{
Expand All @@ -148,11 +143,6 @@ struct etl::is_assignable<Moveable, Moveable> : public etl::true_type
{
};

template <>
struct etl::is_constructible<Moveable> : public etl::true_type
{
};

template <>
struct etl::is_copy_constructible<Moveable> : public etl::false_type
{
Expand All @@ -169,11 +159,6 @@ struct etl::is_assignable<MoveableCopyable, MoveableCopyable> : public etl::true
{
};

template <>
struct etl::is_constructible<MoveableCopyable> : public etl::true_type
{
};

template <>
struct etl::is_copy_constructible<MoveableCopyable> : public etl::true_type
{
Expand Down

0 comments on commit 682606f

Please sign in to comment.