Resolve coderabbit review issues

Added index_sequence utility to support type_list utilities. Added additional index_sequence utilities for completeness
This commit is contained in:
John Wellbelove 2026-02-20 20:03:36 +00:00
parent af47c98dc7
commit 5f5633796e
4 changed files with 113 additions and 38 deletions

View File

@ -210,15 +210,6 @@ namespace etl
//***************************************************************************
namespace private_type_list
{
template <typename TIndexSequence, size_t Index>
struct index_sequence_push_back;
template <size_t... Indices, size_t Index>
struct index_sequence_push_back<etl::index_sequence<Indices...>, Index>
{
using type = etl::index_sequence<Indices..., Index>;
};
template <typename TTypeList, typename T, size_t Index, typename TResult>
struct type_list_indices_of_type_impl;
@ -230,7 +221,7 @@ namespace etl
// If Head is the same as T then append a new index to the result, otherwise no change.
using next_result = etl::conditional_t<etl::is_same<Head, T>::value,
typename index_sequence_push_back<TResult, Index>::type,
etl::index_sequence_push_back_t<TResult, Index>,
TResult>;
public:
@ -379,7 +370,7 @@ namespace etl
#endif
//***************************************************************************
/// Declares a new type_list by selecting types from a given type_list, according to an index sequence.
/// Declares a new type_list by selecting types from a given type_list, according to a list if indices.
//***************************************************************************
template <typename TTypeList, size_t... Indices>
struct type_list_select
@ -440,12 +431,6 @@ namespace etl
using type = type_list<T, TTypes...>;
};
template <typename T>
struct type_list_push_front<T>
{
using type = etl::type_list<T>;
};
template <typename TypeList, typename T>
using type_list_push_front_t = typename type_list_push_front<TypeList, T>::type;
@ -461,12 +446,6 @@ namespace etl
using type = type_list<TTypes..., T>;
};
template <typename T>
struct type_list_push_back<T>
{
using type = etl::type_list<T>;
};
template <typename TypeList, typename T>
using type_list_push_back_t = typename type_list_push_back<TypeList, T>::type;
@ -481,7 +460,7 @@ namespace etl
private:
ETL_STATIC_ASSERT((etl::is_type_list<TTypeList>::value), "TTypeList must be an etl::type_list");
ETL_STATIC_ASSERT(Index <= TTypeList::size, "Index out of range");
ETL_STATIC_ASSERT(Index <= TTypeList::size, "Index out of range");
using index_sequence_for_prefix = etl::make_index_sequence<Index>;
using index_sequence_for_suffix = etl::make_index_sequence_with_offset<Index, TTypeList::size - Index>;

View File

@ -532,13 +532,13 @@ namespace etl
class integer_sequence
{
public:
ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Integral types only");
typedef T value_type;
static ETL_CONSTEXPR size_t size() ETL_NOEXCEPT
{
static ETL_CONSTEXPR size_t size() ETL_NOEXCEPT
{
return sizeof...(Integers);
}
};
@ -577,7 +577,7 @@ namespace etl
using make_index_sequence = typename private_integer_sequence::make_index_sequence<Count, etl::integer_sequence<size_t>>::type;
//***********************************
/// Make an integer sequence with an offset.
/// Make an integer sequence with an offset.
//***********************************
template <size_t Offset, size_t Count>
using make_index_sequence_with_offset = typename private_integer_sequence::offset_index_sequence<Offset, etl::make_index_sequence<Count>>::type;
@ -604,16 +604,69 @@ namespace etl
};
}
// Accepts either a parameter pack of types or a single etl::type_list<T...>
//***********************************
/// Make an index sequence for a parameter pack of types or an etl::type_list<T...>.
/// Accepts either a parameter pack of types or a single etl::type_list<T...>
//***********************************
template <typename... TTypes>
using make_index_sequence_for = typename private_make_index_sequence_for::impl<TTypes...>::type;
//***********************************
/// An index sequence.
//***********************************
template <size_t... Indices>
using index_sequence = etl::integer_sequence<size_t, Indices...>;
//************************************
/// Alias for make_index_sequence_for.
//************************************
template <typename... TTypes>
using index_sequence_for = typename etl::make_index_sequence_for<TTypes...>;
//************************************
/// Pushes an index to the front of an index_sequence.
//************************************
template <typename TIndexSequence, size_t Index>
struct index_sequence_push_front;
template <size_t... Indices, size_t Index>
struct index_sequence_push_front<etl::index_sequence<Indices...>, Index>
{
using type = etl::index_sequence<Indices..., Index>;
};
template <typename TIndexSequence, size_t Index>
using index_sequence_push_front_t = typename index_sequence_push_front<TIndexSequence, Index>::type;
//************************************
/// Pushes an index to the back of an index_sequence.
//************************************
template <typename TIndexSequence, size_t Index>
struct index_sequence_push_back;
template <size_t... Indices, size_t Index>
struct index_sequence_push_back<etl::index_sequence<Indices...>, Index>
{
using type = etl::index_sequence<Indices..., Index>;
};
template <typename TIndexSequence, size_t Index>
using index_sequence_push_back_t = typename index_sequence_push_back<TIndexSequence, Index>::type;
//************************************
/// Concatenates two index_sequences.
//************************************
template <typename TIndexSequence1, typename TIndexSequence2>
struct index_sequence_cat;
template <size_t... Indices1, size_t... Indices2>
struct index_sequence_cat<etl::index_sequence<Indices1...>, etl::index_sequence<Indices2...>>
{
using type = etl::index_sequence<Indices1..., Indices2...>;
};
template <typename TIndexSequence1, typename TIndexSequence2>
using index_sequence_cat_t = typename index_sequence_cat<TIndexSequence1, TIndexSequence2>::type;
#endif
//***************************************************************************
@ -651,9 +704,9 @@ namespace etl
//***************************************************************************
/// in_place disambiguation tags.
//***************************************************************************
//*************************
struct in_place_t
struct in_place_t
{
explicit ETL_CONSTEXPR in_place_t() {}
};
@ -661,9 +714,9 @@ namespace etl
#if ETL_USING_CPP17
inline constexpr in_place_t in_place{};
#endif
//*************************
template <typename T> struct in_place_type_t
template <typename T> struct in_place_type_t
{
explicit ETL_CONSTEXPR in_place_type_t() {}
};
@ -674,7 +727,7 @@ namespace etl
#endif
//*************************
template <size_t Index> struct in_place_index_t
template <size_t Index> struct in_place_index_t
{
explicit ETL_CONSTEXPR in_place_index_t() {}
};
@ -767,7 +820,7 @@ namespace etl
// Creates a static member 'call' that calls the specified functor.
//*****************************************************************************
template <auto& Instance>
struct functor_as_static
struct functor_as_static
{
template <typename... TArgs>
static constexpr auto call(TArgs&&... args)
@ -781,7 +834,7 @@ namespace etl
// Creates a static member 'call' that calls the specified member function.
//*****************************************************************************
template <auto Method, auto& Instance>
struct member_function_as_static
struct member_function_as_static
{
template <typename... TArgs>
static constexpr auto call(TArgs&&... args)

View File

@ -624,7 +624,7 @@ namespace
// Uncomment to generate static_assert error.
//using list = etl::type_list<>;
//using result1 = etl::type_list_pop_front_t<list>;
//using result1 = etl::type_list_pop_back_t<list>;
}
//*************************************************************************

View File

@ -927,5 +927,48 @@ namespace
CHECK_TRUE((std::is_same<seq2, expect2>::value));
CHECK_TRUE((std::is_same<seq4, expect4>::value));
}
//*********************************
TEST(test_index_sequence_push_front_matches_expected)
{
using seq0 = etl::index_sequence<>;
using seq1 = etl::index_sequence<1U, 2U>;
using result0 = etl::index_sequence_push_front_t<seq0, 5U>;
using result1 = etl::index_sequence_push_front_t<seq1, 0U>;
using expect0 = etl::index_sequence<5U>;
using expect1 = etl::index_sequence<1U, 2U, 0U>;
CHECK_TRUE((std::is_same<result0, expect0>::value));
CHECK_TRUE((std::is_same<result1, expect1>::value));
}
//*********************************
TEST(test_index_sequence_push_back_matches_expected)
{
using seq0 = etl::index_sequence<>;
using seq1 = etl::index_sequence<1U, 2U>;
using result0 = etl::index_sequence_push_back_t<seq0, 5U>;
using result1 = etl::index_sequence_push_back_t<seq1, 3U>;
using expect0 = etl::index_sequence<5U>;
using expect1 = etl::index_sequence<1U, 2U, 3U>;
CHECK_TRUE((std::is_same<result0, expect0>::value));
CHECK_TRUE((std::is_same<result1, expect1>::value));
}
//*********************************
TEST(test_index_sequence_cat_matches_expected)
{
using seq0 = etl::index_sequence<>;
using seq1 = etl::index_sequence<0U, 1U>;
using seq2 = etl::index_sequence<2U, 3U>;
using result0 = etl::index_sequence_cat_t<seq0, seq1>;
using result1 = etl::index_sequence_cat_t<seq1, seq2>;
using expect0 = etl::index_sequence<0U, 1U>;
using expect1 = etl::index_sequence<0U, 1U, 2U, 3U>;
CHECK_TRUE((std::is_same<result0, expect0>::value));
CHECK_TRUE((std::is_same<result1, expect1>::value));
}
}
}