473,471 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 1274
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: 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
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.