I'm trying to store objects in one of several container types, the type of the container is known during run-time. The interface of the containers is the same, but the containers are not polymorphic.
What I am trying to do is avoid the extra jump a vtable forces during runtime - by having a variable that should be of the concrete container type.
Consider that I have the containers:
class Vector1<T>
{
T get();
}
class Vector2<T>
{
T get();
}
And I want to have a container that is either Vector1 or Vector2 depending on some run-time parameter.
So my class should be:
Class VectorWrapper
{
Vector1<SomeType> v1;
Vector2<Sometype> v2;
inline Sometype get()
{
**how do I choose between v1 and v2, without the extra jump?**
}
}
Aucun commentaire:
Enregistrer un commentaire