The _Alloc template is used to obtain objects of some type. The container may have an internal need to allocate objects of a different type. For example, when you have a std::list<T, A>, the allocator A is meant to allocate objects of type T but the std::list<T, A> actually needs to allocate objects of some node type. Calling the node type _Ty, the std::list<T, A> needs to get hold of an allocator for _Ty objects which is using the allocation mechanism provided by A. Using
typename _A::template rebind<_Ty>::other
specifies the corresponding type. Now, there are a few syntactic annoyances in this declaration:
- Since
rebindis a member template of_Aand_Ais a template argument, therebindbecomes a dependent name. To indicate that a dependent name is a template, it needs to be prefixed bytemplate. Without thetemplatekeyword the<would be considered to be the less-than operator. - The name
otheralso depends on a template argument, i.e., it is also a dependent name. To indicate that a dependent name is a type, thetypenamekeyword is needed.