Simplify code with 'if constexpr' in C++17

6 years ago
ian $Q__4tgrnLN

https://www.bfilipek.com/2018/03/ifconstexpr.html

Before C++17 we had a few, quite ugly looking, ways to write static if (if that works at compile time) in C++: you could use tag dispatching or SFINAE (for example via std::enable_if). Fortunately, that’s changed, and we can now take benefit of if constexpr!

Let’s see how we can use it and replace some std::enable_if code.

Simplify code with 'if constexpr' in C++17

May 18, 2018, 5:09pm UTC
https://www.bfilipek.com/2018/03/ifconstexpr.html >Before C++17 we had a few, quite ugly looking, ways to write static if (if that works at compile time) in C++: you could use tag dispatching or SFINAE (for example via std::enable_if). Fortunately, that’s changed, and we can now take benefit of if constexpr! >Let’s see how we can use it and replace some std::enable_if code.