Listing 4

// Prime-number generator.

template<int P, int I> struct CIsPrime
{
   enum { result = ( P == 2 ) || ( P % I ) && 
                        CIsPrime<( I > 2 ? P : 0), I-1>::result } ;
} ;
template<> struct CIsPrime<0, 0>
{
   enum { result = true } ;
} ;
template<> struct CIsPrime<0, 1>
{
   enum { result = true } ;
} ;