dimanche 29 novembre 2015

static_assert on array values

Is it possible to have a compile-time check on array values?

example:

typedef enum
{
    dummy0 = 0,
    dummy1,
    dummy2
} eDummyEnum;

typedef struct
{
    eDummyEnum name;
    int value;
} sDummyStruct;

const sDummyStruct array[]=
{
    {dummy0, 3},
    {dummy1, 5},
    {dummy2, 6}
}

Is there any possibility to check if array[dummy1].name == dummy1 at compilation time?

Aucun commentaire:

Enregistrer un commentaire