Converting some "if" statements to "if constexpr"

Issue #383 duplicate
Phil created an issue

Comments (4)

  1. Klaus Iglberger

    Hi Phil!

    You are correct, there is a lot of opportunity to use if constexpr. So far Blaze does not use any if constexpr. The reason is that Blaze is a C++14 library throughout the 3.x releases (see also the “Compiler Compatibility” section on the main Blaze page) and if constexpr is a C++17 feature. Using if constexpr would therefore be a breaking change for many Blaze users (especially some major companies). We will, however, move to C++17 with the 4.0 release and with that will be able to use if constexpr.

    This issue is a duplicate to issue #282. Therefore I’ll close this one as duplicate and keep issue #282 as a reminder. Thanks,

    Best regards,

    Klaus!

  2. Phil reporter

    Thanks for the quick response.

    Just curious, isn’t this a feature that could easily be handled via macros? Similar to other keywords like BLAZE_ALWAYS_INLINE. So for example:

    #if (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L
    # define BLAZE_CONSTEXPR constexpr
    #else
    # define BLAZE_CONSTEXPR
    #endif
    

    and then

    if BLAZE_CONSTEXPR ( PF && IsVectorizable_v<Type> ) 
    {
      // ...
    }
    

    That way it is compatible with both C++14 and C++17 at the same time.

  3. Klaus Iglberger

    Hi Phil!

    You are correct, for these simple cases a macro would be sufficient. However, that is the boring cases that don’t really exploit the real power of if constexpr and don’t really improve the code (other than getting rid of the warnings). if constexpr is primarily interesting for the cases where I can collapse several SFINAE-guarded functions into one. That problem unfortunately cannot be solved by a macro because the resulting code wouldn’t work in C++14 (e.g. conflicting return types, etc.).

    Best regards,

    Klaus!

  4. Log in to comment