SHARE
TWEET

compile time stuff

Putnam Feb 7th, 2019 (edited) 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import std.range : iota;
  2. import std.math : sqrt;
  3.  
  4. bool isPrime(int n)()
  5. {
  6.     static if(n==2)
  7.     {
  8.         return true;
  9.     }
  10.     else static if(n%2==0)
  11.     {
  12.         return false;
  13.     }
  14.     else
  15.     {
  16.         static foreach(int i;iota(3,cast(int)sqrt(cast(real)n),2))
  17.         {
  18.             if(n%i==0)
  19.             {
  20.                 return false;
  21.             }
  22.         }
  23.         return true;
  24.     }
  25. }
  26.  
  27. enum myNum=1000000007;
  28.  
  29. pragma(msg,"myNum is:");
  30. pragma(msg,myNum);
  31. pragma(msg,"is myNum prime?");
  32. pragma(msg,isPrime!myNum);
  33.  
  34. static assert(0,"this program isn't supposed to finish compiling");
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top