Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to perform a move between STL containers

Reply
Thread Tools

How to perform a move between STL containers

 
 
Dennis Jones
Guest
Posts: n/a
 
      01-03-2007
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


 
Reply With Quote
 
 
 
 
=?ISO-8859-15?Q?Juli=E1n?= Albo
Guest
Posts: n/a
 
      01-03-2007
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
 
Reply With Quote
 
 
 
 
Dennis Jones
Guest
Posts: n/a
 
      01-03-2007

"Julián Albo" <> wrote in message
news:...
> 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


 
Reply With Quote
 
Roland Pibinger
Guest
Posts: n/a
 
      01-03-2007
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
 
Reply With Quote
 
Clark S. Cox III
Guest
Posts: n/a
 
      01-03-2007
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

 
Reply With Quote
 
Dennis Jones
Guest
Posts: n/a
 
      01-03-2007

"Clark S. Cox III" <> wrote in message
news:...
> 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


 
Reply With Quote
 
Clark S. Cox III
Guest
Posts: n/a
 
      01-03-2007
Dennis Jones wrote:
> "Clark S. Cox III" <> wrote in message
> news:...
>> 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

 
Reply With Quote
 
Dennis Jones
Guest
Posts: n/a
 
      01-03-2007

"Clark S. Cox III" <> wrote in message
news:...

> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Are sequence containers not a subset of general containers? Sebastian Mach C++ 5 10-06-2012 07:54 PM
nested stl containers - aliasing stl objects without invokingoperator= Andrey Vul C++ 6 10-22-2009 09:00 AM
Containers of iterators vs. containers of references clark.coleman@att.net C++ 7 01-25-2008 01:37 PM
sorting with STL containers containing objects of different subclasses Koen C++ 1 06-30-2003 03:51 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57