By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,124 Members | 950 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,124 IT Pros & Developers. It's quick & easy.

How to perform a move between STL containers

P: n/a
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
Jan 3 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Dennis Jones wrote:
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.

--
Salu2
Jan 3 '07 #2

P: n/a

"Julián Albo" <JU********@terra.eswrote in message
news:45********@x-privat.org...
Dennis Jones wrote:
>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.
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
Jan 3 '07 #3

P: n/a
On Wed, 03 Jan 2007 01:33:52 GMT, "Dennis Jones" wrote:
>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
Jan 3 '07 #4

P: n/a
Roland Pibinger wrote:
On Wed, 03 Jan 2007 01:33:52 GMT, "Dennis Jones" wrote:
>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??
I'm intrigued as to why that seems noteworthy to you.

--
Clark S. Cox III
cl*******@gmail.com
Jan 3 '07 #5

P: n/a

"Clark S. Cox III" <cl*******@gmail.comwrote in message
news:12*************@corp.supernews.com...
Roland Pibinger wrote:
>On Wed, 03 Jan 2007 01:33:52 GMT, "Dennis Jones" wrote:
>>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??

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
Jan 3 '07 #6

P: n/a
Dennis Jones wrote:
"Clark S. Cox III" <cl*******@gmail.comwrote in message
news:12*************@corp.supernews.com...
>Roland Pibinger wrote:
>>On Wed, 03 Jan 2007 01:33:52 GMT, "Dennis Jones" wrote:
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??
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.
Oh, I know that it is both useful and valid, and am questioning neither.
I just wondered what Roland was questioning.

--
Clark S. Cox III
cl*******@gmail.com
Jan 3 '07 #7

P: n/a

"Clark S. Cox III" <cl*******@gmail.comwrote in message
news:12*************@corp.supernews.com...
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
Jan 3 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.