It is right. The conditional statement does not evaluate the operand if necessary.
You make it unnecessarily complicated. Try using operator literal string patterns (which are supported by both Clang and GCC). They were originally planned for C ++ 1Y - the proposal was rejected (I donβt know why, it was made by Richard Smith, and this function is important).
And if this is not portable enough (since at the moment itβs just a compiler extension), you can use binary recursive macros and an rtrim class template like VTMPL :
# define VTMPL_SPLIT_1(s, x) ( x < sizeof(s) ? s[x] : decltype(*s)() ) # define VTMPL_SPLIT_4(s, x) VTMPL_SPLIT_1 (s, x), VTMPL_SPLIT_1 (s, x+1) , VTMPL_SPLIT_1 (s, x+2) , VTMPL_SPLIT_1 (s, x+3) # define VTMPL_SPLIT_16(s, x) VTMPL_SPLIT_4 (s, x), VTMPL_SPLIT_4 (s, x+4) , VTMPL_SPLIT_4 (s, x+8) , VTMPL_SPLIT_4 (s, x+12) # define VTMPL_SPLIT_64(s, x) VTMPL_SPLIT_16 (s, x), VTMPL_SPLIT_16 (s, x+16) , VTMPL_SPLIT_16 (s, x+32) , VTMPL_SPLIT_16 (s, x+48) # define VTMPL_SPLIT_256(s, x) VTMPL_SPLIT_64 (s, x), VTMPL_SPLIT_64 (s, x+64) , VTMPL_SPLIT_64 (s, x+128), VTMPL_SPLIT_64 (s, x+194) # define VTMPL_SPLIT_1024(s, x) VTMPL_SPLIT_256(s, x), VTMPL_SPLIT_256(s, x+256), VTMPL_SPLIT_256(s, x+512), VTMPL_SPLIT_256(s, x+768) # define VTMPL_STRING_IMPL(str, n) vtmpl::rtrim<vtmpl::string<VTMPL_SPLIT_##n(str, 0)>>::type # define VTMPL_STRING(str) VTMPL_STRING_IMPL(str, 64) # define VTMPL_STRING_256(str) VTMPL_STRING_IMPL(str, 256) # define VTMPL_STRING_1024(str) VTMPL_STRING_IMPL(str, 1024)