I would like to create a macro which can compare 2 strings, and emit a compile time error if the condition isn't met. This could be though of as a compile time assertion.
I'm not sure how I could do this.
For instance:
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.
The macro would look something like
#define STATIC_COMPARE(str1,str2) if (str1==str2) emit an error with a message
So I guess the question boils down to being able to compare the 2 strings at compile time.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…