Here is a sample code to clarify what I want to achieve:
template<typename T>
struct Compose{
T some_way_to_make_name_out_of_type(T);
// -------------------^
// It may be some preprocessor hack or something based on templates
};
The reason I want to do this is that there is a way to check if the field of a certain type exists in the class. So I want to unify the names.
The only limitations are
- the name must be unique with respect to type.
- It is preferred not to use external code generation tools like Cog (Boost is OK though)
My goal is to make the way to generalize approach from the code above and make the same Compose
structure, but for any number of types:
template <typename ... ComponentsTypes>
struct Compose {
//....
};
using Compose<int, float, std::string> = ifsType;
ifsType ifs{};
ifs.int_field = 3;
ifs.float_field = 4.0;
ifs.std_string_filed = "hi";
Let's assume that it is never desired to compose two components of the same type.
using Compose<int, int> = iiType; // <-- will not compile