Disclaimer: this is for hobby development - I wouldn't over-engineer this much in a professional endeavor unless asked to do so.
Imagine an N-dimensional surface, such as a line (1D), grid/circle (2D), cube/sphere (3D), etc., where each axis of this surface is finite in that it has a start and end, or wraps around. A good example is the Earth, where there is longitude (wraps around), latitude (starts and ends), and if necessary, height and time (assume a specific start/end for these).
The generalized structure to handle this scenario could be something like this:
typedef NoAxis End;
typedef Axis<End>::NoWrap<0, 365> Time; // one year, if units are in days
typedef Axis<Time>::NoWrap<0, 35000> Height; // sea level to 35k meters
typedef Axis<Height>::NoWrap<-90, 90> Latitude;
typedef Axis<Latitude>::Wrap<-180, 180> Longitude;
The "Axis" class takes a template parameter that is the next axis; this forms a chain of axes, where a special type "NoAxis" begins the chain. Geometric operations, e.g. finding the distance between two points, are performed by accumulating the calculations for each axis.
My question: is there a way, preferably via template metaprogramming, to programatically find the largest order of magnitude that could be multiplied to the extrema of each axis - the idea being to maximize the surface resolution - but not overflow the storage for the type used to contain the values (e.g. don't overflow 32 bits on a 32-bit system, etc.). This order of magnitude must take into account calculating the distance between points on the surface, which involves finding the squared distance.
Once again, the reason to find this order of magnitude is to get the highest resolution possible for a given storage type.