The intent behind template specialization is that you can add specializations to a template even if you're not the author of the template. One might do this because they are the author of a type which is being used by this specialization. The C++ standard library's rules forbid adding declarations to the std
namespace except for template specializations for precisely this reason.
Deduction guides are not like template specializations. They are considered part of the class template's definition, much like constructors and other member functions. As such, they are expected to be written by the creator of the class, typically immediately following the template class's definition. Given these expectations, it doesn't make sense for deduction guides to exist in a scope other than the scope of the template class definition itself.
Basically, you are not meant to be able to add deduction guides to someone else's class templates.
The very first version of the CTAD proposal, as well as every derivative version thereof, focuses on mapping constructor arguments to class template parameters. What will eventually be known as "deduction guides" were first discussed as "Canonical factory functions". But the text around it is particularly telling:
We suggest a notation to allow constructors to specify their template parameters by either explicitly declaring the signatures for any further needed constructor deductions outside the class
Notice how focused the text is on "constructors". These canonical factory functions are maps between constructors and template arguments. They are considered, conceptually at least, to be constructors of a sort. After all, implicit guides are generated from constructors, so it stands to reason that explicit guides are conceptually equivalent to a class constructor.
Indeed, the prototypical example of why you need explicit deduction guides (that is, why you can't rely entirely on implicit guides) is focused on the constructors of the type. Namely, vector
's iterator constructor:
template<typename Iter>
vector(Iter first, Iter last);
A deduction guide is needed to access this constructor because Iter
doesn't obviously map to the template parameters of vector<T, A>
.
The bottom line is this: explicit deduction guides are built around a class's constructors (though those constructors don't have to exist). They exist to map constructor argument types to class template parameters. If you cannot add a constructor to a class from outside of the class's definition, then it stands to reason that you cannot add an explicit deduction guide from outside of the class's definition either.
Obviously explicit guides are written outside of a template class's definition, but the principle is the same: guides are part of a class's interface.
Implicit conversion via operator Typename
does not add a constructor to Typename
. It may permit Typename(other_type)
to work, but as far as the language standard is concerned, this is a copy/move into Typename
. It isn't modifying the definition of Typename
.