I want to generate a constant array power[501] = {1, p % MODER, p*p % MODER, p*p*p % MODER, ..., p^500 % MODER}, of which p is an constant number.
I know I could generate p^n % MODER by using the following code:
template<int a, int n> struct pow
{
static const int value = a * pow<a, n-1>::value % MODER;
};
template<int a> struct pow<a, 0>
{
static const int value = 1;
};
And it does work!
My question is if I could generate the array that I want?
You can use
BOOST_PP_ENUM
as:Output:
See online demo
The line:
expands to this: