473,386 Members | 1,630 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,386 software developers and data experts.

How to perform a move between STL containers

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
7 2659
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

"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
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
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

"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
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Richard Thompson | last post by:
I've got a memory overwrite problem, and it looks as if a vector has been moved, even though I haven't inserted or deleted any elements in it. Is this possible? In other words, are there any...
2
by: Brent Ritchie | last post by:
Hello, I have a problem that's really getting to me. I have an std::vector, and it holds pointers to classes. From these classes I need a refrence to the object that holds the vector, because it...
18
by: Matthias Kaeppler | last post by:
Hi, in my program, I have to sort containers of objects which can be 2000 items big in some cases. Since STL containers are based around copying and since I need to sort these containers quite...
44
by: Josh Mcfarlane | last post by:
Just out of curiosity: When would using std::list be more efficient / effective than using other containers such as vector, deque, etc? As far as I'm aware, list doesn't appear to be...
20
by: Dilip | last post by:
I understand the C++ standard does not talk about threading. My question here is directed more towards what happens when a STL container is used in a certain way. I'd appreciate any thoughts. I...
35
by: dragoncoder | last post by:
Just a simple theoritical question to the experts. What was the rationale behind making STL containers follow copy semantics rather than reference semantics. References almost always make things...
21
by: George Exarchakos | last post by:
Hi everyone, I'd like your help... Can we have a std::list<BASEwhere BASE be the base class of a class hierarchy? I want to add to this list objects that are inherited from BASE class but not...
6
by: Carter | last post by:
This is probably somewhat of a beginners question but I am unfamiliar with alot of aspects of C++. What is the correct way to append multiple STL containers together in constant time. Obviously you...
2
by: Desmodromic | last post by:
Informix recommend that symbolic links be used for chunks. These links are then used in the dbspace definition. Does this advice hold for DB2? The equivalent would be to create symbolic links...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.