STL源文件:
文件:c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xmemory
行:103-107
template<class _Other>
struct rebind
{ // convert an allocator<_Ty> to an allocator <_Other>
typedef allocator<_Other> other;
};
rebind的目的就是定义一个struct (allocator), 这个allocator能分配 _Other类型的元素。
用途:
如std::list<int>的allocator,默认分配的元素类型是int,通过如下定义
见文件:C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\list
typename _Alloc::template rebind<_Node>::other
_Alnod; // allocator object for nodes
};
就可以用_Alnod为list的实际元素_Node 分配空间了,
_Node的定义:
typedef _Node *_Nodeptr; // _Node allocator must have ordinary pointers
struct _Node
{ // list node
_Node()
{ // default constructor, do nothing
}
_Nodeptr _Next; // successor node, or first element if head
_Nodeptr _Prev; // predecessor node, or last element if head
_Ty _Myval; // the stored value, unused if head
};