I am reading about deduction guides in C++17. So say we have the following example:
template<typename T> struct Custom
{
};
template<typename T> struct Person
{
Person(Custom<T> const&);
Person(Custom<T>&&);
};
template<typename T> Person(Custom<T>) -> Person<T>; //explicitly declared deduction guide
My question is that will the explicit declaration for the explicit deduction guide(as shown above) disable the formation of the 2 implicit deduction guides(corresponding to the 2 ctors of class template Person
) that would have been there if we did not specify an explicit deduction guide. I mean, suppose in the above example, there was no explicit deduction guide, then there will be 2 implicit deduction guides(corresponding to the two constructors of Person
). But after we have added explicit guide, will we have a total of 1 deduction guide(explicitly declared by us the user) or 3 deduction guides(including 2 implicit deduction guides).
PS: Note that the question is only about the deduction guides for Person
and not about whether implicit guide will be formed for Custom
.
No, deduction-guide declarations do not suppress the formation of implicit deduction guides during the class template argument deduction process. The overload set will contain both. See [over.match.class.deduct]/1:
However, the third last tiebreaker in the overload resolution process gives precedence to deduction-guides (i.e., explicitly declared deduction guides) over implicit deduction guides. [over.match.best.general]/2.10. This tiebreaker is only reached after all of the more general tiebreakers (not related directly to deduction guides) are tried.