vendredi 26 avril 2019

How to concatenate parameter with colons in macro?

I want to write a macro that generates a vector with a name that consists of the name + type. So, GEN_NAME_TYPE_MEMBER(int, Id) should generate vector<int> vec_Id_int. GEN_NAME_TYPE_MEMBER(std::string, FName) should generate vector<int> vec_Id_string.

The following macro almost does it, but it fails when there is colons

#define GEN_NAME_TYPE_MEMBER(Name, Type)
    std::vector<Type> vec_##Name_##Type;

INITIAL SOLUTION

move the Type to the beginning of the name

 #define GEN_NAME_TYPE_MEMBER(Name, Type)
        std::vector<Type> Type##_##Name_vec;

Is there a way to put at the end of the name?

Aucun commentaire:

Enregistrer un commentaire