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?

1

1 Answer 1

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));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.