I have a Kd-Tree implementation, which is templatized to accept any dimension greater than 0 and any floating-point type (float, double, etc…). Something like this:
template <typename real, size_t dimensions> class KdTree
{
// stuff
}
And I have an accompanying “point” type which has the exact same template layout. However this point type needs to be accessible from outside the kd-tree class. Now, every time I need to create temporary points inside my kd-tree code, I need to explicitly go KdPoint<real, dimensions>, which is tiresome, makes my lines really long, and adds no value whatsoever to the code.
Is there any way I can tell the compiler to implicitly assume whatever values for real and dimensions were passed to the class for the points as well? Linking the two template lists together, in a way. So that I can just type KdPoint and the compiler will directly know what to put in there, based on the template arguments the class received.
Otherwise I’ll need to use a macro to explicitly expand the latter into the former, which kind of sucks.
You could add a typedef to the
KdTreeclass:and use
KdPoint_internally. If you want the point type to be accessible externally, give thetypedefpublic access, and a name that doesn-t end in_:This can then be accessed like this: