You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was just browsing through some of the utilities in ETL, and I noticed that nth_type appears to be implemented incorrectly as of 6780a56f52e38d4d7c095165694905afa202aaa9.
nth_type_helper does not seem to check if it's at the Nth type -- it always falls through to the last type in the variadic set due to what I believe to be an incorrect partial-specialization:
template <size_t N, typename T1, typename... TRest>
structnth_type_helper
{
using type = typename nth_type_helper<N - 1U, TRest...>::type;
};
template <size_t N, typename T1>
structnth_type_helper<N, T1>
{
using type = T1;
};
The size_t N parameter is always decremented, but never checked for a specific value -- so once N = 0 it will just roll over to static_cast<size_t>(-1).
I was just browsing through some of the utilities in ETL, and I noticed that
nth_type
appears to be implemented incorrectly as of 6780a56f52e38d4d7c095165694905afa202aaa9.nth_type_helper
does not seem to check if it's at the Nth type -- it always falls through to the last type in the variadic set due to what I believe to be an incorrect partial-specialization:etl/include/etl/nth_type.h
Lines 42 to 52 in 6780a56
The
size_t N
parameter is always decremented, but never checked for a specific value -- so onceN = 0
it will just roll over tostatic_cast<size_t>(-1)
.This can be tested with:
The first test fails because it yields
long
instead ofint
(Live Example)From inspection, it appears that the partial specialization for
nth_type_helper
should actually be:which I believe is the desired behavior (Live Example)
(I don't have time to clone/make the change/open a PR, but this was quick enough to type up, and should be easy enough to fix)
The text was updated successfully, but these errors were encountered: