#include #include using namespace std; using namespace std::chrono; template struct midpt { static const long long value = I+(J-I)/2; // alternative method of associating a constant value: //enum {value = I+(J-I)/2}; }; template struct isprimehelper { static const bool value = isprimehelper::value>::value && isprimehelper::value+1,J>::value; }; template struct isprimehelper::type> { static const bool value = false; }; template struct isprimehelper=J||I>X/I)>::type> { static const bool value = true; }; template struct isprime { static const bool value = isprimehelper::value; }; template struct nextprime { static const long long value = nextprime::value; }; template struct nextprime::value>::type> { static const long long value = X; }; int main(int argc, char **argv) { cout << "starting program" << endl; // constexpr variable: // must be constructed or assigned a value at declaration // the assigned value or parameteres to the constructor must // only be literals, constexpr variables, or constexpr fns // if a constructor is used, it must be a constexpr constructor auto t1 = high_resolution_clock::now(); long long largishprime = nextprime<1000000>::value; auto t2 = high_resolution_clock::now(); cout << "time = " << duration_cast(t2-t1).count() << " microseconds" << endl; cout << largishprime << endl; // (not possible for TMP) /* long long x; cin >> x; t1 = high_resolution_clock::now(); x = nextprime(x); t2 = high_resolution_clock::now(); cout << "time = " << duration_cast(t2-t1).count() << " microseconds" << endl; cout << x << endl; */ }