mercredi 24 juillet 2019

Want to define list of macros with same prefix

I have a bunch of macros to define with same prefix and I don't want to define them one by one.

Say, I want to define like:

static constexpr str_1 = "str_1";
static constexpr str_2 = "str_2";
....
static constexpr str_100 = "str_100";

I tried:

#define DECLARE_STR(variable_prefix, val_prefix, cur, max) do { \
if ((cur) < (max)) { \
    static constexpr variable_prefix##cur = val_prefix#cur; \
    DECLARE_STR(variable_prefix, val_prefix, cur+1 , max) \
} while(0)

But got errors: error: expected member name or ';' after declaration specifiers

Do I have a correct way to implement this?

Aucun commentaire:

Enregistrer un commentaire