I was wondering about the advantage of std::enable_if
over static_asserts
to prevent template instantiation. This answer suggests, that std::enable_if
allows SFINAE, which is a convincing argument in the case of function templates.
However is this argument legitimate for class templates (and variable templates)? As far as I know, there is no overload resolution involved there, making SFINAE - again, as far as I know - not relevant, but I might be wrong. If so, can you name an example?
If not, I assume static_assert
to be the better solution for the given issue (preventing template instantiation) in the case of class templates, since it's arguably more explicit, concise and readable and allows a custom error message. Is that correct or am I missing a point other than SFINAE?