From ad0773e52214db06a979a2812e93a51d82305dfb Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 22 Feb 2026 21:29:21 +0000 Subject: [PATCH] Modified the "All message IDs must be unique" static_assert to directly use the index_sequence of message IDs Added addition index_sequence utilities to support this change. --- include/etl/message_router.h | 8 +-- include/etl/utility.h | 106 +++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 4 deletions(-) diff --git a/include/etl/message_router.h b/include/etl/message_router.h index b5c9bbdf..02307535 100644 --- a/include/etl/message_router.h +++ b/include/etl/message_router.h @@ -424,7 +424,7 @@ namespace etl { private: - using message_id_types = etl::type_list...>; + using message_id_sequence = etl::index_sequence; public: @@ -432,9 +432,9 @@ namespace etl using message_types = etl::type_list; ///< The message types. using sorted_message_types = etl::type_list_sort_t; ///< The message types sorted by message id. - static_assert(etl::type_list_is_unique::value, "All TMessageTypes must be unique"); - static_assert(etl::type_list_all_of::value, "All TMessageTypes must satisfy the condition etl::is_message"); - static_assert(etl::type_list_is_unique::value, "All message IDs must be unique"); + static_assert(etl::type_list_is_unique::value, "All TMessageTypes must be unique"); + static_assert(etl::type_list_all_of::value, "All TMessageTypes must satisfy the condition etl::is_message_type"); + static_assert(etl::index_sequence_is_unique::value, "All message IDs must be unique"); //********************************************** /// Default constructor. The message router id will be MESSAGE_ROUTER. diff --git a/include/etl/utility.h b/include/etl/utility.h index 6e997f16..f2419023 100644 --- a/include/etl/utility.h +++ b/include/etl/utility.h @@ -762,6 +762,112 @@ namespace etl template inline constexpr size_t index_sequence_at_v = index_sequence_at::value; #endif + + //************************************ + /// Checks if an index_sequence contains a value. + //************************************ + template + struct index_sequence_contains; + + // An empty sequence does not contain any value. + template + struct index_sequence_contains, Value> : etl::false_type + { + }; + + // When the front index of the sequence is the value, the sequence contains the value. + // When the front index of the sequence is not the value, recurse with the tail of the sequence. + template + struct index_sequence_contains, Value> + : etl::integral_constant, Value>::value> + { + }; + +#if ETL_USING_CPP17 + template + inline constexpr bool index_sequence_contains_v = index_sequence_contains::value; +#endif + + //*************************************************************************** + /// Defines a new index_sequence by removing duplicate indexes from a given index_sequence, preserving the first occurrence. + //*************************************************************************** + namespace private_index_sequence + { + template + struct type_index_sequence_impl; + + // When the front index of the sequence is not in the unique sequence, add it to the back of the unique sequence and recurse with the tail of the sequence. + template + struct type_index_sequence_impl, etl::index_sequence> + { + // If the index is already in the unique sequence, do not add it again. Otherwise, add it to the back of the unique sequence. + using type = typename etl::conditional_t, Index>::value, + type_index_sequence_impl, etl::index_sequence>, + type_index_sequence_impl, etl::index_sequence_push_back_t, Index>>>::type; + }; + + // When the sequence is empty, the unique sequence is the result. + template + struct type_index_sequence_impl, etl::index_sequence> + { + using type = etl::index_sequence; + }; + } + + template + struct index_sequence_unique; + + template + struct index_sequence_unique> + { + using type = typename private_index_sequence::type_index_sequence_impl, etl::index_sequence<>>::type; + }; + +#if ETL_USING_CPP11 + template + using index_sequence_unique_t = typename etl::index_sequence_unique::type; +#endif + + //*************************************************************************** + /// Checks that all of the indices in an index_sequence are unique. + //*************************************************************************** + template + struct index_sequence_is_unique; + + template + struct index_sequence_is_unique> + : etl::bool_constant, + etl::index_sequence_unique_t>>::value> + { + }; + +#if ETL_USING_CPP17 + template + inline constexpr bool index_sequence_is_unique_v = index_sequence_is_unique::type::value; +#endif + + //*************************************************************************** + /// Checks if the index_sequence is empty. + //*************************************************************************** + template + struct index_sequence_is_empty; + + template <> + struct index_sequence_is_empty> + : etl::true_type + { + }; + + template + struct index_sequence_is_empty> + : etl::false_type + { + }; + +#if ETL_USING_CPP17 + template + inline constexpr bool index_sequence_is_empty_v = index_sequence_is_empty::value; +#endif #endif //***************************************************************************