-
-
Notifications
You must be signed in to change notification settings - Fork 479
Add traits to type_list #1044
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add traits to type_list #1044
Conversation
|
Removed the review comment. |
| : public etl::integral_constant<size_t, 0> | ||
| { | ||
| }; | ||
|
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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<>?
There was a problem hiding this comment.
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.
include/etl/type_list.h
Outdated
| using type = typename type_list_cat<etl::type_list<TTypes1..., TTypes2...>, TTail...>::type; | ||
| }; | ||
|
|
||
| template<typename TL, typename T> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjusted accordingly.
| { | ||
| }; | ||
|
|
||
| } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
17d9436 to
f43c9e1
Compare
f43c9e1 to
1cdf747
Compare
d4813df
into
ETLCPP:pull-request/#1044-Add-traits-to-type_list
This change adds several traits to type_list.h:
Further: test_type_list.cpp including tests for already existing traits.