Substitution Failure Is Not An Error (SFINAE)
Ran into a lot on my day-to-day work at Tesla, and a little bit at NVIDIA.
Substitution Failure Is Not An Error (SFINAE) applies during overload resolution of templates.
Thereās enable_if
SFINAE states that when substituting the deduced type for the template parameter fails, the specialization is discarded from the overload set instead of causing a compile error.
This piece of code is very hard to underestand for me, from GXF repo
template <class T>
struct AddRvalueReference {
private:
template <class U> static constexpr TypeIdentity<U&&> Test(void*);
template <class U> static constexpr TypeIdentity<U> Test(...);
public:
using type = typename decltype(Test<T>(nullptr))::type;
};
Resources