title: How to check a value like "#define VERSION 3.1.4" at compile time?
body: <p>I am adding compile-time checks to my company's C++ projects to make sure the third-party libraries on all development machines and build servers are up-to-date. Most libraries define something like the following for e.g. version 3.1.4:</p>
  
  <pre><code>#define VERSION_MAJOR 3
  #define VERSION_MINOR 1
  #define VERSION_BUILD 4
  </code></pre>
  
  <p>This is nice and easy to check using <code>static_assert</code> or preprocessor directives.</p>
  
  <p>Now I am looking at a third-party library that defines a single macro instead:</p>
  
  <pre><code>#define VERSION 3.1.4
  </code></pre>
  
  <p><strong>How can I verify the value of such a macro at compile time?</strong></p>
  
  <hr>
  
  <p>With C++11, I could use a <code>constexpr</code> string comparison function, and stringify the macro to check it:</p>
  
  <pre><code>constexpr bool static_equal(const char * a, const char * b)
  {
      return (*a == *b) &amp;&amp; (*a == '\0' || static_equal(a + 1, b + 1));
  }
  
  // stringification functions
  #define str(x) #x
  #define xstr(x) str(x)
  
  static_assert(static_equal(xstr(VERSION), "3.1.4"), "incorrect version of libwhatever");
  </code></pre>
  
  <p>But we are using Visual Studio 2013 on the Windows machines, so I can only use the subset of C++11 that it supports. Unfortunately <code>constexpr</code> is not supported.</p>