Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Usage: g++ isPrime.cpp -std=c++0x -DmaxNumber=XX
- template <int Num, int Now=Num-1>
- struct isPrime
- {
- const static bool Ask =
- Num%Now==0 ? false : isPrime<Num, Now-1>::Ask;
- };
- template <int Num>
- struct isPrime<Num, 1>
- {
- const static bool Ask=true;
- };
- template <int Num>
- struct Try
- {
- Try<Num-1> Fake;
- static_assert(!isPrime<Num>::Ask, "is a prime number.");
- };
- template <>
- struct Try<1>
- {
- };
- int main(int argc, char* argv[])
- {
- //enum {maxNumber=10};
- Try<maxNumber>();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement