lundi 28 décembre 2020

Why does this SFINAE not work with enable_if even when the substitution fails?

template <typename Types>
class C {
using A = typename Types::A;
using B = typename Types::B;

template <typename Dummy = void>
inline typename std::enable_if<std::is_same<A, B>::value, Dummy>::type f(vector<int>& ctx, const string& r) { }
};

When I try to compile the above code when A and B are not same, I get the following error:

test.h:153:12: note:   template argument deduction/substitution failed:
test.h:153:12: error: no type named ‘type’ in ‘struct std::enable_if<false, void>’

Note that the code I have presented is not the exact code I use and the variable and function names have been altered to protect secrecy

Aucun commentaire:

Enregistrer un commentaire