Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between boost::split vs boost::iter_split

Tags:

c++

boost

What is the difference between boost::split and boost::iter_split functions?

like image 885
Ivan Ivanov Avatar asked Dec 26 '13 07:12

Ivan Ivanov


1 Answers

boost::split copies the split string into the SequenceSequenceT (for example, a std::vector<std::string>). boost::iter_split places iterators (specifically, iterator ranges) into the SequenceSequenceT.

This effectively means two things:

  1. Using split will create copies, hence any changes to the returned container of strings won't be seen by the original string. Also, you don't need to worry about iterator invalidation.

  2. Using iter_split will give back a container of iterator ranges, hence, modifying what these iterators point to will also modify the original string. Secondly, if the original string is modified after you run iter_split, you could run into iterator invalidation issues. However, no copies are performed on the underlying string, so this will likely run slightly faster and use less memory.

like image 84
Yuushi Avatar answered Sep 24 '22 05:09

Yuushi