#include #include /* WILL NOT COMPILE!!!!! */ 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 = X%I!=0 && (I>=J || I>X/I || (isprimehelper::value>::value && isprimehelper::value+1,J>::value)); }; template struct isprime { static const bool value = isprimehelper::value; }; template struct nextprime { static const long long value = isprime::value ? X : nextprime::value; }; 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<100000>::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; */ }