The if constexpr
syntax introduced with C++17 should work with the /std:c++14
compiler switch, according to this documentation: C++17 Features In Visual Studio 2017 Version 15.3 Preview.
However, it does not work. Instead, the following compiler error is generated:
error C4984: 'if constexpr' is a C++17 language extension
Is the documentation wrong?
If so, how can if constexpr
be compiled in Visual Studio 2017 15.3?
Yes. I believe putting such const ness is always a good practice wherever you can. For example in your class if a given method is not modifying any member then you always tend to put a const keyword in the end. Now putting constexpr suggests that get() must also be a constexpr .
In a constexpr if statement, the value of condition must be a contextually converted constant expression of type bool (until C++23)an expression contextually converted to bool, where the conversion is a constant expression (since C++23).
Looks like the documentation linked in the question is inaccurate here.
To use if constexpr
in Visual Studio 2017, you need to compile with either the /std:c++17
or /std:c++latest
switch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With