allocator::rebind

某个类型的对象的赋值程序分配另一类型的对象存储的结构。

template<class _Other>
   struct rebind {
   typedef allocator<_Other> other;
   };

参数

  • 其他
    分配内存时元素的类型。

备注

此结构为随不同实现的容器的元素类型的类型的内存很有用。

成员模板选件类定义其他类型。其唯一目的是提供类型名称 allocator<_*** 其他 ***>类型名称命名为 allocator<*** 类型 ***>。

例如命名分配器对象类型 Aal,可以指定类型 _Other 对象与该表达式的:

A::rebind<Other>::other(al).allocate(1, (Other *)0)

或者,可以通过将类型命名其指针类型:

A::rebind<Other>::other::pointer

示例

// allocator_rebind.cpp
// compile with: /EHsc
#include <memory>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef vector<int>::allocator_type IntAlloc;
int main( ) 
{
   IntAlloc v1Iter;
   vector<int> v1;

   IntAlloc::rebind<char>::other::pointer pszC =
      IntAlloc::rebind<char>::other(v1.get_allocator()).allocate(1, (void *)0);

   int * pInt = v1Iter.allocate(10);
}

要求

标头: <memory>

命名空间: std

请参见

参考

allocator Class