Difference between boost::split vs boost::iter_spl

2019-06-21 04:28发布

问题:

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

回答1:

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.



标签: c++ boost