Advertisement Jump to content
Sign in to follow this  
aaron_ds

std::copy, boost::shared_ptr

This topic is 4964 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 was working around with std::containers filled with boost::shared_ptr and noticed that some code failed on std::copy. Here's an example
std::vector < boost::shared_ptr < int  > > v1;
  std::vector < boost::shared_ptr <  int  > > v2;
  v1.push_back(boost::shared_ptr < int  >( new  int ));
  v1.push_back(boost::shared_ptr < int  >( new  int ));
  v1.push_back(boost::shared_ptr < int  >( new  int ));



//this works fine
for(std::vector < boost::shared_ptr < int  > >::iterator itr=v1.begin(); itr!=v1.end(); ++itr){
    v2.push_back(*itr);
  }



//this doesn't work
std::copy(v1.begin(), v1.end(), v2.begin());



//this doesn't work
std::copy(v1.begin(), v1.end(), v2.end());



It also works if the destination vector already has an element in it. Strange. It seems as though I can only std::copy to a vector that already has elements in it. I'd really like to be able to use std::copy(v1.begin(), v1.end(), v2.end()); instead of a for loop. Is there any reason why I cant copy v1 to v2? The program segfaults in boost::shared+ptr's assignment operator. Thank You

Share this post


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

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!