C++ 對映庫 - get_allocator() 函式



描述

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

宣告

以下是來自 std::map 標頭檔案的 std::map::get_allocator() 函式宣告。

C++98

allocator_type get_allocator() const;

C++11

allocator_type get_allocator() const noexcept;

引數

返回值

返回與 map 關聯的分配器。

異常

此成員函式從不丟擲異常。

時間複雜度

常數,即 O(1)

示例

以下示例演示了 std::map::get_allocator() 函式的用法。

#include <iostream>
#include <map>

using namespace std;

int main(void) {
   map<char, int> m;
   pair<const char, int> *p;

   p = m.get_allocator().allocate(5);

   cout << "Allocated size = " <<  sizeof(*p) * 5 << endl;

   return 0;
}

讓我們編譯並執行上面的程式,這將產生以下結果:

Allocated size = 40
map.htm
廣告
© . All rights reserved.