From f1777dce37cc2945e0697ae3ec3413ecd37b5d27 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 16 May 2019 23:23:13 +0100 Subject: [PATCH] Added variadic 'is_one_of' --- include/etl/type_traits.h | 42 ++++++++++++++++++++++++----- include/etl/type_traits_generator.h | 23 ++++++++++++++++ 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index ee01e614..43be133e 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -314,6 +314,13 @@ namespace etl template struct is_trivially_copy_assignable : etl::is_pod {}; #endif +#if ETL_CPP11_SUPPORTED + /// is_rvalue_reference + ///\ingroup type_traits + template struct is_rvalue_reference : etl::false_type {}; + template struct is_rvalue_reference : etl::true_type {}; +#endif + /// conditional ///\ingroup type_traits template struct conditional { typedef T type; }; @@ -335,7 +342,7 @@ namespace etl struct conditional_integral_constant { ETL_STATIC_ASSERT(etl::is_integral::value, "Not an integral type"); - static const T value = FALSE_VALUE; + static const T value = FALSE_VALUE; }; /// make_signed @@ -480,19 +487,40 @@ namespace etl ///\ingroup type_traits template <> struct alignment_of : integral_constant {}; +#if ETL_CPP11_SUPPORTED + + //***************************************************************************" + /// Template to determine if a type is one of a specified list. + ///\ingroup types + //***************************************************************************" + template + struct is_one_of + { + static const bool value = etl::is_same::value || + etl::is_one_of::value; + }; + + template + struct is_one_of + { + static const bool value = etl::is_same::value; + }; + +#else + //*************************************************************************** /// Template to determine if a type is one of a specified list. ///\ingroup types //*************************************************************************** template struct is_one_of { - static const bool value = + static const bool value = etl::is_same::value || etl::is_same::value || etl::is_same::value || @@ -512,6 +540,8 @@ namespace etl etl::is_same::value; }; +#endif + //*************************************************************************** // A set of templates to allow related types to be derived. //*************************************************************************** diff --git a/include/etl/type_traits_generator.h b/include/etl/type_traits_generator.h index 83b982bd..5c237cac 100644 --- a/include/etl/type_traits_generator.h +++ b/include/etl/type_traits_generator.h @@ -499,6 +499,27 @@ namespace etl ///\ingroup type_traits template <> struct alignment_of : integral_constant {}; +#if ETL_CPP11_SUPPORTED + + //***************************************************************************" + /// Template to determine if a type is one of a specified list. + ///\ingroup types + //***************************************************************************" + template + struct is_one_of + { + static const bool value = etl::is_same::value || + etl::is_one_of::value; + }; + + template + struct is_one_of + { + static const bool value = etl::is_same::value; + }; + +#else + /*[[[cog import cog cog.outl("//***************************************************************************") @@ -524,6 +545,8 @@ namespace etl ]]]*/ /*[[[end]]]*/ +#endif + //*************************************************************************** // A set of templates to allow related types to be derived. //***************************************************************************