Skip to content

Commit

Permalink
Variadic versions of etl::type_id_lookup and etl::type_type_lookup fo…
Browse files Browse the repository at this point in the history
…r C++11 and above.
  • Loading branch information
jwellbelove committed May 21, 2020
1 parent 59c389b commit 8c22c5c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions include/etl/generators/type_traits_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,7 @@ namespace etl
//***************************************************************************
/// index_of
//***************************************************************************
#if ETL_CPP11_SUPPORTED
template <typename T, typename... TTypes>
class index_of
{
Expand All @@ -1569,27 +1570,28 @@ namespace etl
template <typename Type, typename T1, typename... TRest>
struct index_of_helper
{
static const size_t value = etl::is_same<Type, T1>::value ? 1 : 1 + index_of_helper<Type, TRest...>::value;
static constexpr size_t value = etl::is_same<Type, T1>::value ? 1 : 1 + index_of_helper<Type, TRest...>::value;
};

//***********************************
template <typename Type, typename T1>
struct index_of_helper<Type, T1>
{
static const size_t value = 1;
static constexpr size_t value = 1;
};

public:

static_assert(etl::is_one_of<T, TTypes...>::value, "T is not in typelist");

static const size_t value = index_of_helper<T, TTypes...>::value - 1;
static constexpr size_t value = index_of_helper<T, TTypes...>::value - 1;
};

#if ETL_CPP17_SUPPORTED
template <typename T, typename... TTypes>
inline constexpr size_t index_of_v = index_of<T, TTypes...>::value;
#endif
#endif
}

#endif // ETL_TYPE_TRAITS_INCLUDED
8 changes: 5 additions & 3 deletions include/etl/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,7 @@ namespace etl
//***************************************************************************
/// index_of
//***************************************************************************
#if ETL_CPP11_SUPPORTED
template <typename T, typename... TTypes>
class index_of
{
Expand All @@ -1562,27 +1563,28 @@ namespace etl
template <typename Type, typename T1, typename... TRest>
struct index_of_helper
{
static const size_t value = etl::is_same<Type, T1>::value ? 1 : 1 + index_of_helper<Type, TRest...>::value;
static constexpr size_t value = etl::is_same<Type, T1>::value ? 1 : 1 + index_of_helper<Type, TRest...>::value;
};

//***********************************
template <typename Type, typename T1>
struct index_of_helper<Type, T1>
{
static const size_t value = 1;
static constexpr size_t value = 1;
};

public:

static_assert(etl::is_one_of<T, TTypes...>::value, "T is not in typelist");

static const size_t value = index_of_helper<T, TTypes...>::value - 1;
static constexpr size_t value = index_of_helper<T, TTypes...>::value - 1;
};

#if ETL_CPP17_SUPPORTED
template <typename T, typename... TTypes>
inline constexpr size_t index_of_v = index_of<T, TTypes...>::value;
#endif
#endif
}

#endif // ETL_TYPE_TRAITS_INCLUDED

0 comments on commit 8c22c5c

Please sign in to comment.