當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


C++ Deque get_allocator()用法及代碼示例


描述

C++ 函數std::deque::get_allocator()返回與 deque 關聯的分配器。

聲明

以下是 std::deque::get_allocator() 函數形式 std::deque 頭文件的聲明。

C++98

allocator_type get_allocator() const;

C++11

allocator_type get_allocator() const noexcept

參數

返回值

返回與 deque 關聯的分配器。

異常

此成員函數從不拋出異常。

時間複雜度

常數,即 O(1)

示例

下麵的例子展示了 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

相關用法


注:本文由純淨天空篩選整理自 C++ Deque Library - get_allocator() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。