Better way to un-define a set of defines based on version numbers in C++?
While it's somewhat uncertain whether you'll like it (some compilers warn about doing so) it's entirely permissible to #undef a value that wasn't defined to start with, so you can consolidate these down to something like:

#if OPENGL_TARGET_VERSION &lt; 44
    #undef GL_VERSION_4_4
#endif

#if OPENGL_TARGET_VERSION &lt; 43
    #undef GL_VERSION_4_3
#endif

#if OPENGL_TARGET_VERSION &lt; 42
    #undef GL_VERSION_4_2
#endif

#if OPENGL_TARGET_VERSION &lt; 41
    #undef GL_VERSION_4_1
#endif


While this does (or at least sort of might) answer the question you asked, from a code review standpoint, I'd probably prefer the code as it's written in the question. It's longer, but:


it's almost certainly hidden in a header almost nobody really reads through very often
it's simple repetitions of a simple pattern, so reading it isn't much work,
eliminating the #ifdef will give warnings with some compilers

While I think that's a pretty stupid warning, eliminating the warning is still worth more than reducing the line count.