std::pair allocator?

C

codigo

Mark P said:
Why doesn't std::pair have an allocator?

A std::pair is not a container. Its purpose is not to allocate. Think of a
std::pair as a record-template for inserting or extracting a record-pair to
/ from a given associative container. Its the associative container that
handles or stores the allocation of a std::pair's contents.
 
M

Mark P

Andrew said:
If it had one, how would it use it?
I'm not sure :) I read on the SGI website, "A pair is much like a
Container, in that it 'owns' its elements." But I guess the concept of
an allocator only makes sense for containers which can grow in size or
contents, whereas any pair instance is of a fixed size?
 
J

James Dennett

Mark said:
I'm not sure :) I read on the SGI website, "A pair is much like a
Container, in that it 'owns' its elements." But I guess the concept of
an allocator only makes sense for containers which can grow in size or
contents, whereas any pair instance is of a fixed size?

Right. Dynamic allocation isn't needed when the number of items
is known at compile time (though in other such cases it may be
desirable for other reasons, such as limited stack space).

-- James
 
R

Rolf Magnus

Mark said:
I'm not sure :) I read on the SGI website, "A pair is much like a
Container, in that it 'owns' its elements." But I guess the concept of
an allocator only makes sense for containers which can grow in size or
contents, whereas any pair instance is of a fixed size?

Basically, yes. allocators give containers a way to (surprise!) allocate
memory, but std::pair doesn't allocate memory. It's basically just
something like:

template <typename First, typename Second>
struct pair
{
First first;
Second second;
};

Not really much use for an allocator here. ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top