Reputation:
Is there any way to use a custom allocator with a map of maps?
I.e 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?
I.e for the outer I would do:
Allocator myAllocator;
Outer outer(std::less<int>(), myAllocatorObject);
For the inner??
Upvotes: 1
Views: 1292
Reputation: 3035
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:
The very nice remake version by Jonathan Wakely:
Upvotes: 2