1

I would like to use a different allocator than the default one in unordered_map.
For my specific allocator, I want to call another constructor than the default one (I want to pass an int to the constructor).
I think the problem is that unordered_map calls the default constructor of my allocator.

So, Eventually I want to do something like that:

Instead of calling this unordered_map constructor:

std::tr1::unordered_map<int, int, std::tr1::hash<int>, std::equal_to<int>, MyAllocatorNs::MyAllocator<std::pair<const int, int> > > unorderedMap;

I want to do something like that:

std::tr1::unordered_map<int, int, std::tr1::hash<int>, std::equal_to<int>, MyAllocatorNs::MyAllocator<std::pair<const int, int> >(3) > unorderedMap;

Is it possible anyhow?

hudac
  • 2,584
  • 6
  • 34
  • 57
  • 1
    [Will passing the allocator instance in the map constructor work for you?](http://en.cppreference.com/w/cpp/container/unordered_map/unordered_map) – milleniumbug Mar 04 '15 at 11:27

1 Answers1

2

unordered_map allows you to pass in an instance of the allocator as an argument rather than defaulting to the zero-argument constructor.

typedef MyAllocatorNs::MyAllocator<std::pair<const int, int> > AllocatorType;
unordered_map<int, int, hash<int>, equal_to<int>, AllocatorType > unorderedMap (AllocatorType(3));
TartanLlama
  • 63,752
  • 13
  • 157
  • 193