I was wondering, is it possible to make a list of types using template programming, with methods to iterate over them etc.?
Essentially im looking for an equivalent of a simple std container except for arbitrary types and defined at compile time.
I want to do compile time polymorphism.
GameObjectContainer<Contained<Player, MAP>, Contained<Tree, VECTOR>> objects; *For each type of game object i can define what kind of data structure is most suitable in a compact form. The non template alternative is manually defining these things within the game object container, as well as manually updating the objects.update() etc. to account for new containers to go through. int index1=objects.add<Player>(); *Adds to MAP<Player> int index2=objects.add<Tree>(); *Adds to VECTOR<Tree> Player p=objects.get<Player>(index1); *Accesses map Tree t=object.get<Tree>(index2); *Accesses vector objects.update(); *Goes through both map and vector automatically, i never need to update how this method works.
As you can see this would be only to reduce the amount of code in well defined situations. How would i implements something like this in the cleanest way?
Is there a C++ object that can contain a list of types and has a for_each method that runs a lambda for each element (with each element being of different type, im not sure if lambdas work for this?)