We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Specifying default allocator

Unimatrix_001
on
Medium Priority
253 Views
Last Modified: 2012-05-07
Hello.

If I have something like vector<int>, there is a default allocator given, I know that uses new(), but say I'm creating a new container class, how can I specify to use the default allocator as the STL container classes do?

template<typename TAllocator=???>

Thanks,
Uni
Comment
Watch Question

evilrixSenior Software Engineer (Avast)
CERTIFIED EXPERT

Commented:
typedef vector<int, MyAllocator> MyVecType;
evilrixSenior Software Engineer (Avast)
CERTIFIED EXPERT

Commented:
Sorry.. mis read... I'll try again...
evilrixSenior Software Engineer (Avast)
CERTIFIED EXPERT

Commented:
struct MyAllocator // Must model an allocator concept
{
};

template < typename T, typename aT = MyAllocator>
struct MyVector
{
};

Author

Commented:
But how about if I'm wanting the default allocator provided by the STL - i.e. vector<int> uses new(). How do I go about doing that?
Senior Software Engineer (Avast)
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Ah thank you. :)
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.