mercredi 26 juin 2019

Generate unique values for global constexpr variables

I am using global constexpr as keys to access a map, and I was wondering if there was a way to automatically initialize them with the next available integer.

constexpr size_t ON_EVENT_X = 0;
constexpr size_t ON_EVENT_Y = 1;
constexpr size_t ON_EVENT_Z = 2;

Is it possible, given ON_EVENT_X, ON_EVENT_Y and ON_EVENT_Z to automatically initialize them with the correct values ? I think it could be done with a preprocessor macro but I haven't used it enough to know exactly how.

Any suggestions ?

Thanks!

Aucun commentaire:

Enregistrer un commentaire