473,395 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Re: a few stl container questions: allocators and comparers.

sheam wrote:
Ok one last question on using my custom allocator with std::map:

should the allocator's value_type template argument be of type
pair<mykey,myvalor just myval type? Both seem to compile and run fine.

i.e.,

map< int,
Test,
less<const int>,
CustomAllocator<Test my_map;

or

map< int,
Test,
less<const int>,
CustomAllocator<pair<const int,Test my_map;
Is the 'rebind' struct making them functionally equivilant?

Thanks.

~S
Jun 27 '08 #1
3 1272
sheam wrote:
sheam wrote:
Ok one last question on using my custom allocator with std::map:

should the allocator's value_type template argument be of type
pair<mykey,myvalor just myval type? Both seem to compile and run fine.

i.e.,

map< int,
Test,
less<const int>,
CustomAllocator<Test my_map;

or

map< int,
Test,
less<const int>,
CustomAllocator<pair<const int,Test my_map;
Is the 'rebind' struct making them functionally equivilant?

Thanks.

~S

In fact, I get same results if I do this:
map< int,
Test,
less<const int>,
CustomAllocator<float my_map;

????

~S
Jun 27 '08 #2
sheam wrote:
sheam wrote:
>sheam wrote:
Ok one last question on using my custom allocator with std::map:

should the allocator's value_type template argument be of type
pair<mykey,myvalor just myval type? Both seem to compile and run fine.

i.e.,

map< int,
Test,
less<const int>,
CustomAllocator<Test my_map;

or

map< int,
Test,
less<const int>,
CustomAllocator<pair<const int,Test my_map;
This would be the usual choice.

>Is the 'rebind' struct making them functionally equivilant?

Thanks.

~S


In fact, I get same results if I do this:
map< int,
Test,
less<const int>,
CustomAllocator<float my_map;
The default allocator type is std::alloctor< value_type >. Internally,
std::map has to use nodes that are not of type value_type. Therefore, it ha
to use a rebind trick to get the right allocator type. That is the reason
why it could compile with float.

However, the standard says that

std::map< Key, T, C, A >::reference

is a typedef for A::reference. The same goes for pointer, const_reference,
and const_pointer. As soon as you use these, the first and last version
should fail.
Best

Kai-Uwe Bux
Jun 27 '08 #3
Kai-Uwe Bux wrote:
>
However, the standard says that

std::map< Key, T, C, A >::reference

is a typedef for A::reference. The same goes for pointer, const_reference,
and const_pointer. As soon as you use these, the first and last version
should fail.
Thanks. I noticed that it was essentially resulting an allocation of
std::pair, so that is what I was using.

~S
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike Krasnik | last post by:
Hello all, I've been messing with checking memory leaks last time, and it looks like some of the memory was not freed due to the fact "library's default allocators keep free memory in a pool for...
11
by: Vivi Orunitia | last post by:
Hi all, I tried looking this up in the sgi docs but it didn't provide any concrete answer to what I'm looking for. Basically, is there any difference between using ::iterator for a container vs...
18
by: Mark A. Gibbs | last post by:
I'm having yet another headache with making a standard allocator. What behaviour should be expected from the assigment operator? When would it be called? Why is it there at all, when you can't...
7
by: jose luis fernandez diaz | last post by:
Hi, Is this right any stl container (vector, deque, list, . . .)? typedef vector container; int main() { container<int> c1;
16
by: forester | last post by:
lets say its common situation when object have subobjects in container and receives callbacks from contained items. and object want to move objects in containers on signal(callback). iterator is...
6
by: daveb | last post by:
I'm trying to write some code that calls the constructors of STL containers explicitly, and I can't get it to compile. A sample program is below. One compiler complains about the last two lines...
2
by: wolverine | last post by:
Hi Me being a beginner in c++ , i just want to know is their anything special i have to take care when using container inside a container. eg: vector inside a map which is inside a map When...
7
by: toton | last post by:
Hi, I want a circular buffer or queue like container (queue with array implementation). Moreover I want random access over the elements. And addition at tail and remove from head need to be low...
3
by: yasmin | last post by:
I am dealing with internal memory fragmentation issues in my program (C++ program on freeBSD). It involves a large number of fixed-size structures. For example for my records which are typically...
3
by: Rob McDonald | last post by:
I am interested in having a container which has properties of both the STL's list and vector. (I want my cake and to eat it too). In my application, I will need to add/remove items from arbitrary...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.