简体   繁体   中英

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


The very nice remake version by Jonathan Wakely:

http://ideone.com/wBtaks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM