Vorrei creare una macro che possa confrontare 2 stringhe ed emettere un errore di compilazione se la condizione non è soddisfatta. Questo potrebbe essere come un'asserzione del tempo di compilazione.Come confrontare statisticamente due stringhe di caratteri al momento della compilazione
Non sono sicuro di come potrei farlo.
Per esempio:
STATIC_COMPARE("THIS STRING","THIS STRING") -> would emit a compile time error
STATIC_COMPARE("THIS STRING","THIS OTHER STRING) -> wouldn't emit a compile time error.
La macro sarebbe simile
#define STATIC_COMPARE(str1,str2) if (str1==str2) emit an error with a message
Quindi credo che la questione si riduce ad essere in grado di confrontare le 2 stringhe in fase di compilazione.
State assumendo stringa pool letterale anche legato alla [lunghezza Computing di una stringa C in fase di compilazione. È davvero un constexpr?] (Http://stackoverflow.com/q/25890784/1708801) –