[英]Map of maps and custom allocator
Is there any way to use a custom allocator with a map of maps? 有没有办法在地图上使用自定义分配器?
Ie let's say I have: 即假设我有:
typedef std::map<int,int> Inner;
typedef std::map<int, Inner> Outer;
Can I have a custom allocator for both? 我可以为两者都使用自定义分配器吗?
How can I do that since I cannot define the allocator for the inner map in the constructor of the inner map? 由于无法在内部映射的构造函数中为内部映射定义分配器,该怎么办?
Ie for the outer I would do: 即对于外部我会做:
Allocator myAllocator;
Outer outer(std::less<int>(), myAllocatorObject);
For the inner?? 对于内心?
It looks like this: 看起来像这样:
typedef std::map<int, int, std::less<int>, SimpleAllocator<std::pair<const int, int>>> Inner;
typedef std::map<int, Inner, std::less<int>, SimpleAllocator<std::pair<const int, Inner>>> Outer;
Inner inner;
Outer outer;
I've tried some sample code here and it works: 我在这里尝试了一些示例代码,它可以工作:
http://ideone.com/CuoaiQ http://ideone.com/CuoaiQ
The very nice remake version by Jonathan Wakely: Jonathan Wakely的非常好的翻版版本:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.