目录

deque::get_allocator

描述 (Description)

C ++函数std::deque::get_allocator()返回与deque关联的分配器。

声明 (Declaration)

以下是std :: deque :: get_allocator()函数形式std :: deque header的声明。

C++98

allocator_type get_allocator() const;

C++11

allocator_type get_allocator() const noexcept

参数 (Parameters)

没有

返回值

返回与deque关联的分配器。

异常 (Exceptions)

该成员函数从不抛出异常。

时间复杂

常数即O(1)

例子 (Example)

以下示例显示了std :: deque :: get_allocator()函数的用法。

#include <iostream>
#include <deque>
using namespace std;
int main(void) {
   deque<int> d = {1, 2, 3, 4, 5};
   int *p = NULL;
   p = d.get_allocator().allocate(5);
   for (int i = 0; i < 5; ++i)
      p[i] = i + 1;
   cout << "Contents of deque are" << endl;
   for (int i = 0; i < 5; ++i)
      cout << p[i] << endl;
   return 0;
}

让我们编译并运行上面的程序,这将产生以下结果 -

Contents of deque are
1
2
3
4
5
↑回到顶部↑
WIKI教程 @2018