template<
bool R,
long M,
template<long>class T
>struct Selector_Ext
{
typedef T<M> RType;
};
template<
long M,
template<long>class T
>struct Selector_Ext<false,M,T>
{
typedef typename Selector_Ext<T<M + 1>::IsPrime,M + 1,T>::RType RType;
};
template<long N,long M = 2>struct Generate_Ext
{
typedef typename Selector_Ext<Prime<M>::IsPrime,M,Prime>::RType RType;
static void Go(){ //generate the next N prime number(s) from M
RType();
Generate_Ext<N - 1,RType::Number + 1>::Go();
}
};
template<long M>struct Generate_Ext<0,M>
{
static void Go(){}
};
int main(){
Generate_Ext<8,5>::Go();
}
产生从5开始的8个素数,即5,7,11,13,17,19,23,29。
744

被折叠的 条评论
为什么被折叠?



