How to get the i-th integer in a integer parameter pack? For example
template<int... Is>
struct A
{
enum { CONSTANT_0 = Is[0] }; //Assume the sizeof...(Is) > the index requested
};
Like that:
template <size_t I, int N, int... R>
struct pick : pick <I - 1, R...> { };
template <int N, int... R>
struct pick <0, N, R...> : std::integral_constant <int, N> { };
so that
pick <3, 1, 2, 3, 4, 5, 6>::value
equals 4, and
template<int... Is>
struct A
{
enum { CONSTANT_0 = pick <0, Is...>::value };
};
is how you would use it in your case.
Another way:
template <size_t I, int... N>
using pick = typename std::tuple_element <I,
std::tuple <std::integral_constant <int, N>...>
>::type;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With