How to perform a move between STL containers

D

Dennis Jones

Hi,

Is there is a way to *move* elements from one container to another with a
single STL function? That is, can I move an element (or range of elements)
between containers without doing a copy followed by a remove?

I've got two containers (a queue and a list) holding shared_ptr's, and I'd
like to move elements back and forth between them. I only need to move one
element at a time, though I suspect a general solution would also accept a
range.

Thanks,

Dennis
 
?

=?ISO-8859-15?Q?Juli=E1n?= Albo

Dennis said:
I've got two containers (a queue and a list) holding shared_ptr's, and I'd
like to move elements back and forth between them.

What problem are you trying to solve? Using smart pointers copying and
deleting causes no problem. If you want to do it with a single function,
write that function.

There is the splice function that does what you want, but just for lists of
the same type. This makes sense because the list implementation can use his
internal implementation details to do it in a way much more efficient than
a external function can do.
 
D

Dennis Jones

Julián Albo said:
What problem are you trying to solve? Using smart pointers copying and
deleting causes no problem. If you want to do it with a single function,
write that function.

There is the splice function that does what you want, but just for lists
of
the same type. This makes sense because the list implementation can use
his
internal implementation details to do it in a way much more efficient than
a external function can do.

No problem in particular...I'm just looking for the appropriate built-in
solution, if one exists (instead of writing my own) -- no sense reinventing
the wheel if it's already invented!

- Dennis
 
R

Roland Pibinger

Is there is a way to *move* elements from one container to another with a
single STL function? That is, can I move an element (or range of elements)
between containers without doing a copy followed by a remove?
I've got two containers (a queue and a list) holding shared_ptr's,

shared_ptr's in STL containers??
and I'd
like to move elements back and forth between them. I only need to move one
element at a time, though I suspect a general solution would also accept a
range.

For list look at the splice functions, for queue you are out of luck.

Best wishes,
Roland Pibinger
 
D

Dennis Jones

Clark S. Cox III said:
I'm intrigued as to why that seems noteworthy to you.

Me too -- I'm not sure if Clark is questioning its usefulness or its
validity.

In either case, Clark, it's both useful and valid.

- Dennis
 
C

Clark S. Cox III

Dennis said:
Me too -- I'm not sure if Clark is questioning its usefulness or its
validity.

In either case, Clark, it's both useful and valid.

Oh, I know that it is both useful and valid, and am questioning neither.
I just wondered what Roland was questioning.
 
D

Dennis Jones

Oh, I know that it is both useful and valid, and am questioning neither.
I just wondered what Roland was questioning.

Oh, sorry! :) I was intending to refer to "Roland" (not "Clark") since he
was the one that asked the question. Too early in the morning for me, I
guess!

- Dennis
 

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,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top