Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Specifying default allocator

Posted on 2009-07-10
6
Medium Priority
?
242 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
0
Comment
Question by:Unimatrix_001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 40

Expert Comment

by:evilrix
ID: 24828602
typedef vector<int, MyAllocator> MyVecType;
0
 
LVL 40

Expert Comment

by:evilrix
ID: 24828605
Sorry.. mis read... I'll try again...
0
 
LVL 40

Expert Comment

by:evilrix
ID: 24828610
struct MyAllocator // Must model an allocator concept
{
};

template < typename T, typename aT = MyAllocator>
struct MyVector
{
};
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:Unimatrix_001
ID: 24828616
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?
0
 
LVL 40

Accepted Solution

by:
evilrix earned 2000 total points
ID: 24828641
>> vector<int> uses new()
No, vector uses std::allocator

std::vector<T, std::allocator<T> >

template < typename T, typename aT = std::allocator<T> >
struct MyVector
{
};
0
 
LVL 3

Author Closing Comment

by:Unimatrix_001
ID: 31602330
Ah thank you. :)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question