Grade. You can define a pi like this:
template <class T> constexpr double pi = 3.14159...; template <> constexpr long double pi<long double> = 3.14159...L; template <> constexpr float pi<float> = 3.14159...F;
But you must specify which pi you want:
float f2 = sqrt(f * pi<float>); double d2 = sqrt(d * pi<double>);
More specifically, you can define some pi object that simply overloaded operator* depending on the type:
struct Pi { template <class T> decltype(pi<T>) operator*(T val) { return val * pi<T>; } template <class T> friend decltype(pi<T>) operator*(T val, Pi) { return pi<T> * val; } };
This allows you to get the syntax you want, but it's weird, don't do this.
source share