mercredi 14 septembre 2016

C++ partial ordering for a function with default argument

Consider the following code:

template <class...>
using void_t = void;

template <class T>
void bar(T){}

template <class T>
void bar(T, void_t<decltype(std::declval<T>().foo())>* = 0) {}

struct A { void foo(); } a;
bar(a); // gives a compiler error on ambiguous call

So the question is, why are these overloads ambiguous? Why is the second overload not considered to be more restrictive, more specialized than second one by the compiler?

Aucun commentaire:

Enregistrer un commentaire