This could be an easy answer to what I am facing, but I have tried my best the search previous posts, but none directly maps to what I need. The code below has a master (bmGsNoSuff
) and slave (bmGsNoSuffHelper
) . The Idea is, I want to pass the variable j
from bmGsNoSuff
such that it gets used by the inner called struct bmGsNoSuffHelper
. It turns out, I cannot do this so long as j
has been declared as a parameter of bmGsNoSuff
's constructor. The compiler alarms : error: ‘j’ cannot appear in a constant-expression bmGsNoSuffHelper<I,j>()(BmGs, suff, i );
What could be the way out of this? How can I pass j
from the master to the helper?
template<typename I , int j>
struct bmGsNoSuffHelper
{
void operator () ( I BmGs[], I suff[] ,int i )
{
if ( j < size - 1 -i ){
if(BmGs[j]==size){
BmGs[j]=size-1-i;
}
bmGsNoSuffHelper<I,j+1>()(BmGs, suff, i ); // InitialiseBmGs<I,i+1> () ( BmGs);
}
}
};
template<typename I>
struct bmGsNoSuffHelper<I, size>
{
void operator () (I BmGs[], I suff[], int i ) {}
};
//BmGsNoSuff
template<typename I , int i>
struct bmGsNoSuff
{
void operator () ( I BmGs[], I suff[], int j )
{
if ( i >=-1 ){
if((i==-1) || ( suff[i] == i+1)){
bmGsNoSuffHelper<I,j>()(BmGs, suff, i );
}
bmGsNoSuff<I,i-1>()( BmGs, suff, j + 1 );
}
}
};
template<typename I>
struct bmGsNoSuff<I, -2>
{
void operator () (I BmGs[], I suff[] , int j) {}
};