You cannot in the preprocessor, but you can abuse character traits!
VS 2013 seems to support variation patterns. Try using the CSTRING macro at fooobar.com/questions/52916 / ... (you can replace constexpr with const and have the code still working) and do something like:
#define STRT(x) decltype(CSTRING(x)) static_assert(std::is_same<STRT(VERSION), STRT("3.1.4")>::value, "incorrect version of libwhatever");
EDIT: This does not work. However, if your compiler compiles this without errors:
extern const char data[] = "abc"; template <char C> struct x { static const char c = C; }; char buf[(int)x<"ABC123"[0]>::c]; int main() { return (int)buf; }
Then you can try the following:
#include <type_traits> #define VERSION 1.2.3 #define STR2(x) #x #define STR(x) STR2(x) template <char...> struct ststring; // https://stackoverflow.com/a/15860416/2097780 #define MACRO_GET_1(str, i) \ (sizeof(str) > (i) ? str[(i)] : 0) #define MACRO_GET_4(str, i) \ MACRO_GET_1(str, i+0), \ MACRO_GET_1(str, i+1), \ MACRO_GET_1(str, i+2), \ MACRO_GET_1(str, i+3) #define MACRO_GET_16(str, i) \ MACRO_GET_4(str, i+0), \ MACRO_GET_4(str, i+4), \ MACRO_GET_4(str, i+8), \ MACRO_GET_4(str, i+12) #define MACRO_GET_64(str, i) \ MACRO_GET_16(str, i+0), \ MACRO_GET_16(str, i+16), \ MACRO_GET_16(str, i+32), \ MACRO_GET_16(str, i+48) #define MACRO_GET_STR(str) MACRO_GET_64(str, 0), 0 static_assert(std::is_same<ststring<MACRO_GET_STR(STR(VERSION))>, ststring<MACRO_GET_STR("1.2.3")>>::value, "invalid library version");