Skip to content

Conversation

@rolandreichweinbmw
Copy link
Collaborator

This change adds several traits to type_list.h:

  • type_list_contains
  • type_list_index_of
  • type_list_max_sizeof_type (long name to prevent confusion with type_list_size)
  • type_list_max_alignment

Further: test_type_list.cpp including tests for already existing traits.

@jwellbelove
Copy link
Contributor

Removed the review comment.
I thought I'd had it compiling OK with etl::is_one_of, but I hadn't.

: public etl::integral_constant<size_t, 0>
{
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A corresponding 'type from index' class should be implemented.

template<typename TypeList, size_t Index>
struct type_list_type_at

i.e.

using TypeList = etl::type_list<char, short, int>;
using second_type = etl::type_list_type_at<TypeList, 1>::type; // short

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that available via the already implemented etl::nth_type<>?

Copy link
Contributor

@jwellbelove jwellbelove Mar 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, yes, but that's a much older class, originally designed for a narrower use case.
I think a class named consistently with other type_list_x classes could be less confusing.
There is another etl::type_list style class called etl::parameter_pack which will eventually be deprecated, as etl::type_list covers everything it does, and more.

using type = typename type_list_cat<etl::type_list<TTypes1..., TTypes2...>, TTail...>::type;
};

template<typename TL, typename T>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer TypeList over TL

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted accordingly.

{
};

}
Copy link
Contributor

@jwellbelove jwellbelove Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For C++17, add _v definitions for types that return a value
i.e.

#if ETL_USING_CPP17
  template<typename TL, typename T>
  inline constexpr bool type_list_contains_v = etl::type_list_contains<TL, T>::value;
#endif

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted accordingly.

{
};

template<typename T>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this give the same index for the first type in a non-empty type_list, and an empty type_list?

using NonEmpty = etl::type_list<char, int>;
using Empty    = etl::type_list<>;

size_t nonEmptyIndex = etl::type_list_index_of<NonEmpty, char>::value;

size_t emptyIndex = etl::type_list_index_of<Empty, char>::value;

nonEmptyIndex == emptyIndex

Maybe add static constexpr size_t npos = etl::integral_limits<size_t>::max; to etl::type_list<> and return etl::type_list<>::npos for emptyIndex.

For the furture, I'm thinking that an ETL generic etl::npos may be useful

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted accordingly.

The "npos" is implemented as etl::type_list_npos. Reasoning:

  • etl::type_list<>::npos causes linker errors on application level / unit tests since the symbol needs to be defined in a single compile unit and in ETL we only work header-only. This is different from plain global symbols, or in an abstract template.
  • etl::npos causes compile warnings and therefore errors because etl::basic_string_view::npos shadows etl::npos

@rolandreichweinbmw rolandreichweinbmw force-pushed the type-list-members branch 2 times, most recently from 17d9436 to f43c9e1 Compare March 7, 2025 14:50
@jwellbelove jwellbelove changed the base branch from master to pull-request/#1044-Add-traits-to-type_list March 9, 2025 09:41
@jwellbelove jwellbelove merged commit d4813df into ETLCPP:pull-request/#1044-Add-traits-to-type_list Mar 9, 2025
63 checks passed
jwellbelove pushed a commit that referenced this pull request Mar 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants