Home C&C++函数库 c++ 语法 程序源码 Linux C库

std::

list::get_allocator

公众成员函数  <list>
1)
allocator_type get_allocator() const;
(2)
allocator_type get_allocator() const noexcept;

获取分配器

返回与列表容器关联的分配器对象的副本。

☲  参数


none

☉  返回值



分配器 .
成员类型allocator_type是容器使用的分配器类型,在列表中定义为第二个模板参数(Alloc)的别名。

☣  示例



// list::get_allocator
#include <iostream>
#include <list>

int main ()
{
  std::list<int> mylist;
  int * p;

  // allocate an array of 5 elements using mylist's allocator:
  p=mylist.get_allocator().allocate(5);

  // assign some values to array
  for (int i=0; i<5; ++i) p[i]=i;

  std::cout << "The allocated array contains:";
  for (int i=0; i<5; ++i) std::cout << ' ' << p[i];
  std::cout << '\n';

  mylist.get_allocator().deallocate(p,5);

  return 0;
}

该示例展示了使用与容器相同的分配器为整型数组分配内存的详细方法.
输出:
The allocated array contains: 0 1 2 3 4

✥ 复杂度



常量

☣ 迭代器的有效性



不变

⇄ 数据竞争


容器被访问。
不访问所包含的元素:并发访问或修改它们是安全的。

☂ 异常安全性



No-throw保证:这个成员函数从不抛出异常。
复制默认分配器的任何实例化也保证不会抛出。

🍄  另请参阅



allocator 默认分配器(类模板)

联系我们 免责声明 关于CandCplus 网站地图