jeudi 28 avril 2016

Static dispatching to correct member method with hierarchies of aggregate types

I have written a small in-house framework which does something akin to:

Group<ObjectA1, ObjectA2> groupA(data);
Group<ObjectB> groupB(data);

// Compiles, as desired:
groupA.get<ObjectA1>();
groupA.get<ObjectA2>();
groupB.get<ObjectB>();

// Compilation errors (static asserts), as desired:
groupA.get<ObjectB>();
groupB.get<ObjectA1>();
groupB.get<ObjectA2>();

However, I'm struggling to extend it with the following abilities:

// ...continued...

using GroupA = Group<ObjectA1, ObjectA2>;
using GroupB = Group<ObjectB>;
AggregateGroup<GroupA, GroupB> group(groupA, groupB);

// Compiles, as desired
group.get<ObjectA1>();
group.get<ObjectA2>();
group.get<ObjectB>();

// Compilation error, as desired:
group.get<ObjectC>();

This can be generalized to groups consisting of other groups. Runtime solutions are easy, but I'm at a loss on how to do this at compile time.

Question: How can we create hierarchies of aggregate types that statically dispatch to the correct member?

PS: If a minimal version of my current implementation is required, please indicate so and I will update the question accordingly.

Aucun commentaire:

Enregistrer un commentaire