Quantcast
Channel: User HolyBlackCat - Stack Overflow
Viewing all articles
Browse latest Browse all 946

Answer by HolyBlackCat for How to compare string when precompile

$
0
0

You have two options:

  1. Use numbers instead of strings, and give them names using macros:

    #define HELLO 1#define ASDASD 2#define MY_MACRO HELLO#if MY_MACRO == HELLO// ...#endif
  2. Don't use preprocessor, use a plain if (or if constexpr, the only difference here is that the latter forces the condition to be a compile-time constant). This means that all branches have to be valid (have to compile) regardless of which one is choosen:

    #define MY_MACRO "hello"int main(){    if constexpr (MY_MACRO == std::string_view("hello"))    {    }}

    Or make MY_MACRO a global constexpr std::string_view variable if you don't need to override it with compiler flags.


Viewing all articles
Browse latest Browse all 946

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>