您的位置:首页 > 其它

容器的allocator(容器配置器)(一)

2016-02-28 14:53 411 查看
#include <iostream>
#include <map>
using namespace std;
// 函数Get_allocator用于返回map/multimap的内存配置器,
// 内存配置器类似指针的首地址,用于指明对象的初始存储位置,
// 获取容器的内存分配器至关重要
void main()
{
typedef map<int, double> MAP;
// 定义allocator容器配置器
MAP::allocator_type m1_alloc; //map<int, double>::allocator_type ma_alloc;
MAP::allocator_type m2_alloc;
MAP::allocator_type m3_alloc;
MAP::allocator_type m4_alloc;

// 定义容器(map容器类对象),get_allocator为成员函数
MAP m1, m2, m3;
m1_alloc = m1.get_allocator();// 原型:allocator_type get_allocator() const
m2_alloc = m2.get_allocator();
m3_alloc = m3.get_allocator();

// 把m1的容器配置器存储m4
MAP m4(less<int>(), m1_alloc);
// 获取m4的容器配置器
m4_alloc = m4.get_allocator();

// 检查m4和m1的容器配置器是否相同
if (m4_alloc == m2_alloc)
{
cout << "配置器相同" << endl;
}
else
cout << "配置器不相同" << endl;
cin.get();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: