slice a std::list

This topic is 4726 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I'm haveing a hard time finding much info on this. Is their a way to take a chunk of one std::list and attach to another std::list without allocating memory. Right now i have a quad tree and im sending a list through it to find objects that have bounding box collision with the box i send through. Problem is that after finding a box collisions i have to push_back( the object ) when with a custom list i could get away with just a few pointer assignements. ive seen 2 functions splice and merge but it doenst seem like they do what i need. If anyone has any info id appreciate it.

Share on other sites
Have a look at the c++ standard. It's been translateed into HTML and put on the web somewhere. Try google.

Share on other sites
What exactly is wrong with splice?

CM

Share on other sites
nothing it seems like what im looking for. I was under the impression that it aloocated memory but it seems like i was wrong.

Share on other sites
Quote:
 Original post by Raymond_Porter420nothing it seems like what im looking for. I was under the impression that it aloocated memory but it seems like i was wrong.

No. list::splice only does a bit of pointer tweaking. The elements you're splicing are taken out of the original list and spliced into the target list.

Share on other sites
splice does what you want:

#include <iostream>#include <list>#include <functional>#include <algorithm>using namespace std;int data123[] = { 1 , 2 , 3 };int data456[] = { 4 , 5 , 6 };int main ( int argc , char ** argv ) {    list< int > a( data123 , data123 + 3 );    list< int > b( data456 , data456 + 3 );    ostream_iterator< int > osi( cout );    copy( a.begin() , a.end() , osi ); //prints 123    copy( b.begin() , b.end() , osi ); //prints 456    a.splice( a.end() , b ); //splices the contents of b into a before a.end(), which being past the end, inserts the contents of b at the end of a.    copy( a.begin() , a.end() , osi ); //prints 123456}

EDIT: Beaten to the punch :P.

Share on other sites
Quote:
 Original post by NitageHave a look at the c++ standard. It's been translateed into HTML and put on the web somewhere. Try google.

[wow] i highly doubt that, if it has that can't be legal, C++ 2003 TC1 at ISO site costs a fortune then you check ANSI online store PDF is only \$8-12 [lol].

unless you where referring to C++ 98 which is alittle dated.

Share on other sites
Quote:
 unless you where referring to C++ 98 which is alittle dated.

The drafts were on the net.

• 16
• 9
• 13
• 41
• 15