Jump to content
  • Advertisement
Sign in to follow this  
Raymond_Porter420

slice a std::list

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

If you intended to correct an error in the post then please contact us.

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 this post


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

Share this post


Link to post
Share on other sites
Quote:
Original post by Raymond_Porter420
nothing 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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Nitage
Have 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 this post


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


The drafts were on the net.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!