I'm trying to reverse the order of a template-variadic std::size_t
parameter sequence, based on an answer found in a previous thread. But for some reason it doesn't work.
Here's a regular variadic print function:
template<typename = void>
void print(void)
{
std::cout << std::endl;
}
template<typename... T>
void print(std::size_t index, T... indexes)
{
std::cout << index << ' ';
print(indexes...);
}
And here's the template class chain:
template<std::size_t... Indexes>
class NonRecursiveClass
{
public:
void show(void)
{
print(Indexes...);
}
};
template<std::size_t Count, std::size_t Index, std::size_t... Indexes>
class RecursiveClass;
template<std::size_t Count, std::size_t Index, std::size_t... Indexes>
class RecursiveClass : public RecursiveClass<Count - 1u, Indexes..., Index>
{
};
template<std::size_t Index, std::size_t... Indexes>
class RecursiveClass<0u, Index, Indexes...> : public NonRecursiveClass<Index, Indexes...>
{
};
Basically, the idea is that if you create, for instance, a RecursiveClass<5u, 10u, 1u, 6u, 478u, 23u>
object, it will inherit from a NonRecursiveClass<23u, 478u, 6u, 1u, 10u>
object and you have your std::size_t
parameter sequence backward at compile time.
Unfortunately when I try it out, I still get the original order. Here's my main function:
int main(void)
{
RecursiveClass<5u, 10u, 1u, 6u, 478u, 23u> foo;
foo.show();
return 0;
}
And here's the output:
10 1 6 478 23
What did I do wrong?