Using constexpr if

Discover how constexpr if makes SFINAE easier after C++17 in this lesson.

Introduction to constexpr if

There’s a C++17 feature that makes SFINAE much easier. It’s called constexpr if, and it’s a compile-time version of the if statement. It helps replace complex template code with simpler versions. Let’s start by looking at a C++17 implementation of the serialize function that can uniformly serialize both widgets and gadgets:

Get hands-on with 1400+ tech skills courses.