Tutorial: Conditionally disabling non-template functions
Consider that you have a function template that takes a parameter on type T
.
If the function template has a rather generic name like operator==
, is a constructor,
or anything whose existence might be queried with type traits to further constrain other functions,
it is often beneficial if you can conditionally disable the function if the type does not have some required properties.
Otherwise the function will be “greedy” and accept more than it should - making some traits near useless,
as they only check for existence and the error only occurs later.
Conditionally removing functions if their template parameters don’t fulfill certain properties is done with SFINAE. But what if you have member functions of a class template that are not templates themselves?
» read more »