I am looking for a way to dynamically build a type list at compile time. I am creating components holding different types and under the hood I'd like to build a type list that holds all the types registered as components. Imagine the following:
using Name = Component<std::string>;
using Position = Component<Vec2f>;
I'd then like to be able to end up with a type list which holds std::string and Vec2f in this case that I can access and expand, i.e. something like this:
using AllComponents = SomeMagicTypeThatHoldsAllComponents;
I build the typelist portion already and it works something like this:
using List = typename MakeTypeList<int, double, std::string>::List;
You can append or prepend a type to List like this:
using Append = typename AppendType<List, float>::List;
using Prepend = typename PrependType<List, Vec2f>::List;
And get types by index like this (which basically allows you to expand the types with the help of std::integer_sequence):
using FirstType = typename TypeAt<List, 0>::Type;
The issue I can't wrap my head around is how to dynamically build this list in the background without breaking the simple Component API. Does anybody have suggestions if or how this could be achieved?
EDIT: To Clarify, the only solution I could come up with for now is to pass the type list along as an extra template argument, i.e.
using AllTypes = using MakeTypeList<>::List;
using Name = Component<AllTypes, std::string>;
using Position = Component<AllTypes, Vec2f>;
I am interested in a solution where I don't have to pass the typelist along.
Thank you!