std::basic_string
's deduction guides allow the user to use the std::basic_string
name without specifying its template parameters. Users are also allowed to create their own deduction guides. Assume that the user wants to recreate std::basic_string
. Sooner or later they will be tasked with implementing deduction guides. However, a note from cppreference makes me wonder whether it is at all possible. The note in question says:
These deduction guides are provided for
std::basic_string
to allow deduction from astd::basic_string_view
. Thesize_type
parameter type in (3) refers to thesize_type
member type of the type deduced by the deduction guide. These overloads participate in overload resolution only if Alloc satisfies Allocator.
Emphasis mine.
Can a user implement such a requirement? How can a programmer refer to aliases of the deduced type?
The "type deduced by the deduction guide" is just the type to the right of the
->
:Seems like it's just a shorthand for writing all the template arguments again, especially in places where the deduced type would be much longer, like
unordered_set<typename std::iterator_traits<InputIt>::value_type, std::hash<typename std::iterator_traits<InputIt>::value_type>, std::equal_to<typename std::iterator_traits<InputIt>::value_type>, Alloc>
.