There's more...
static_assert and std::enable_if can be used to achieve the same goals. In fact, in the previous recipe, Performing compile-time assertion checks with static_assert, we have defined the same class template pod_wrapper and function template mul(). For these examples, static_assert seems like a better solution because the compiler emits better error messages (provided that you specify relevant messages in the static_assert declaration). These two, however, work quite differently and are not intended as alternatives.
static_assert does not rely on SFINAE and is applied after overload resolution is performed. The result of a failed assert is a compiler error. On the other hand, std::enable_if is used to remove candidates from ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access