c++ - 未使用自定义分配器
问题描述
考虑以下代码:
#include <map>
#include <iostream>
#include <string>
class MyAlloc : public std::allocator<std::pair<const int, std::string>>
{
public:
MyAlloc()
{
std::cout << "my alloc ctor" << std::endl;
}
};
int main()
{
std::map<int, std::string, std::less<int>, MyAlloc> ms;
ms.insert(std::make_pair(2, "hi"));
std::cout << ms[1] << std::endl;
return 0;
}
我已经创建了我的分配器来适应默认的分配器。但我看到我的分配器没有被使用,甚至没有被构造。
当我使用调试器时,我可以看到map
它使用的是默认值std::allocator
。
我的分配器有问题吗?
解决方案
推荐阅读
- java - Oracle Java - 将可选日期参数添加到 Prepared 语句
- javascript - 'user-input'.is 不是函数
- javascript - 如何根据选中复选框获取多个客户 ID?
- vue.js - 当我调用 this.$router.push() 时浏览器挂起
- python - 编译时的 Tkinter 按钮回调参数
- java - 员工 - 净工资
- regex - 正则表达式查找以下集合中不存在的所有匹配项
- javascript - PQGrid 自动对焦单元
- python-3.x - 在 python 中更快地读取大型 xlsb 文件
- python - 如何转换python数据框,以便将唯一的行值转置为列,另一列的值成为它们的行