Something like "if constexpr" but for class definition
<p><code>if constexpr</code> is a big step for getting rid of preprocessor in C++ programs. However it works only in functions - like in this example:</p>
<pre><code>enum class OS
{
    Linux,
    MacOs,
    MsWindows,
    Unknown
};

#if defined(__APPLE__)
constexpr OS os = OS::MacOs;
#elif defined(__MINGW32__)
constexpr OS os = OS::MsWindows;
#elif defined(__linux__)
constexpr OS os = OS::Linux;
#else
constexpr OS os = OS::Unknown;
#endif

void printSystem()    
{
    if constexpr (os == OS::Linux)
    {
        std::cout &lt;&lt; &quot;Linux&quot;;
    }
    else if constexpr (os == OS::MacOs)
    {
        std::cout &lt;&lt; &quot;MacOS&quot;;
    }
    else if constexpr (os == OS::MsWindows)
    {
        std::cout &lt;&lt; &quot;MS Windows&quot;;
    }
    else
    {
        std::cout &lt;&lt; &quot;Unknown-OS&quot;;
    }
}
</code></pre>
<p>But dreams about getting rid of preprocessor are not quite satisfied - because the following examples do not compile:</p>
<p><strong>1</strong> Cannot use it in class definition to define some members of class differently:</p>
<pre><code>class OsProperties
{
public:
    static void printName()
    {
        std::cout &lt;&lt; osName;
    }
private:
    if constexpr (os == OS::Linux)
    {
        const char* const osName = &quot;Linux&quot;;
    }
    else if constexpr (os == OS::MacOs)
    {
        const char* const osName = &quot;MacOS&quot;;
    }
    else if constexpr (os == OS::MsWindows)
    {
        const char* const osName = &quot;MS Windows&quot;;
    }
    else
    {
        const char* const osName = &quot;Unknown&quot;;
    }
};
</code></pre>
<p><strong>2</strong> Nor it works for not class-scope (like global scope):</p>
<pre><code>if constexpr (os == OS::Linux)
{
    const char* const osName = &quot;Linux&quot;;
}
else if constexpr (os == OS::MacOs)
{
    const char* const osName = &quot;MacOS&quot;;
}
else if constexpr (os == OS::MsWindows)
{
    const char* const osName = &quot;MS Windows&quot;;
}
else
{
    const char* const osName = &quot;Unknown&quot;;
}
</code></pre>
<p>I am (almost) sure this is per C++17 specification that <code>if constexpr</code> works only within function bodies - but my questions are:</p>
<p><strong>Q1</strong> How to achieve the similar effect like <code>if-constexpr</code> in functions - for class and global scope in C++1z/C++14? And I am not asking here for yet another explanation of template specialization... But something that has similar simplicity as <code>if constexpr</code>...</p>
<p><strong>Q2</strong> Are there any plan to extend C++ for the above mentioned scopes?</p>