Class Template Specializations
In addition to specializing function templates, we can also specialize class templates. As an example, we’ll define a specialization of the library hash
template that we can use to store Sales_data
objects in an unordered container. By default, the unordered containers use hash<key_type>
(§ 11.4, p. 444) to organize their elements. To use this default with our own data type, we must define a specialization of the hash
template. A specialized hash
class must define
• An overloaded call operator (§ 14.8, p. 571) that returns a size_t
and takes an object of the container’s key type
• Two type members, result_type
and argument_type
, which are the return and argument types, respectively, of the call operator
• The default ...
Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.