Q:

Compile-time typename aliasing for templates

In my collision/physics engine, I know what spatial partitioning method I'm using at runtime, thanks to templates. I'm trying to create a generic Query class that allows me to perform the same queries on any spatial partitioning method. Every spatial partitioning method implements its own version of the query, but the interface is the same.
The problem is that the user has to specify the spatial partitioning type, the query type of the spatial partitioning type, and the query mode of the spatial partitioning type.
If the user were to change its spatial partitioning method, all the existing code would break.
Is there a way to allow the user to only specify the spatial partitioning type, a generic query type, and a generic query mode and have some kind of aliasing so that the correct type (relative to the spatial partitioning type) is selected automatically?
I've tried using (C++11 typedef) and decltype along with partial specializations, but I couldn't find a correct way to write the code and I never got it to compile/work.
I can only think about using virtual methods and a base class - but that seems unnecessary since I "know" the types at compile-time.

Current code:
 // Query.h
 template<class T, class U, class V>
 Query<T, U, V> getQuery() { return Query<T, U, V>(getSpatial<T>()); } 

 // Example.cpp (user project)
 getQuery<Grid, GridQueryType::Point, GridQueryMode::All>(); 
 getQuery<QuadTree, QuadTreeQueryType::Point, QuadTreeQueryMode::All>();

Desired code (not valid):
 // Query.h
 namespace Type { struct Point; }
 namespace Mode { struct All; }
 template<class T, class U, class V>
 Query<T, typename T::U, typename T::V> getQuery() 
 { 
      return Query<T, typename T::U, typename T::V>(getSpatial<T>()); 
 } 

 // Grid.h
 using Type::Point = GridQueryType::Point;
 using Mode::All = GridQueryMode::All;

 // QuadTree.h
 using Type::Point = QuadTreeQueryType::Point;
 using Mode::All = QuadTreeQueryMode::All;

 // Example.cpp (user project)
 getQuery<Grid, Type::Point, Mode::All>(); // actually uses GridQueryType::Point and GridQueryMode::All!
 getQuery<QuadTree, Type::Point, Mode::All>(); // actually uses QuadTreeQueryType::Point and QuadTreeQueryMode::All!

Real code also passes typename... TArgs to allow query-type-specific parameters - I excluded it from the example for space reasons.

A:

If there is a directly relationship from your first template parameter to the second and the third it seems the latter ones shouldn't be taken as template parameters but be determined from a type-map:
template <typename> struct TypePoint;
template <typename> struct ModeAll

template <> struct TypePoint<Grid> { typedef GridQueryType::Point type; };
template <> struct ModeAll<Grid>   { typedef GridQueryMode::All type; };

getQuery<Grid>();

At least, using a typemap as above you could define default values for the arguments. In case additional arguments are meant to follow, you could basically group the three first arguments together with their defaults into a type which is passed instead, e.g.:
template <typename T,
          typename P = typename TypePoint<T>::type,
          typename M = typename ModeAll<T>::type>
struct QueryParameters {
    typedef T type;
    typedef P point_type;
    typedef M mode_type;
};
getQuery<QueryParemeters<Grid>, Other, Paremters>();

