Boost C++ Libraries: Ticket #3461: bug in iter_split or nth_finder https://svn.boost.org/trac10/ticket/3461 <p> There appears to be a bug in iter_split or nt_finder. </p> <p> Sample code: #include &lt;iostream&gt; #include &lt;string&gt; #include &lt;vector&gt; #include &lt;boost/algorithm/string.hpp&gt; </p> <p> int main() { </p> <blockquote> <p> std::string str("Hello, world, !!!"); std::vector&lt;std::string&gt; slist; </p> </blockquote> <blockquote> <p> boost::algorithm::iter_split(slist, str, boost::algorithm::nth_finder(", ", 0)); </p> </blockquote> <blockquote> <p> for(int index=0; index&lt;str.length(); ++index) </p> <blockquote> <p> std::cout &lt;&lt; slist[index] &lt;&lt; std::endl; </p> </blockquote> </blockquote> <blockquote> <p> return 0; </p> </blockquote> <p> } </p> <p> Output: Hello world !!! </p> <p> Expected Output: Hello world, !!! </p> <p> All other indices seem to work, only when you use 0. </p> <p> This also happens on boost 1.37.0, so its possible it could be in every version in between. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3461 Trac 1.4.3 anonymous Thu, 17 Sep 2009 15:05:07 GMT <link>https://svn.boost.org/trac10/ticket/3461#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3461#comment:1</guid> <description> <p> Sorry about the formatting. Output and Expected output should have been -<br /> </p> <p> Output:<br /> Hello<br /> world<br /> !![[BR]] <br /> </p> <p> Expected Output:<br /> Hello<br /> world, !![[BR]] </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Pavol Droba</dc:creator> <pubDate>Thu, 17 Sep 2009 18:11:31 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/3461#comment:2 https://svn.boost.org/trac10/ticket/3461#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> Hello, </p> <p> The described behavior is perfectly correct. I'm afraid you've misunderstood the semantics of iter_split. If works as follows: </p> <ol><li>set the start marker to the beginning of the sequence </li><li>using the supplied finder, find the first splitter after the marker </li><li>return the match between start marker and splitter </li><li>move the start marker at the end of splitter and goto 2. </li></ol><p> On other words, using nth_finder with iter-split will not split the sequence in two parts, rather it will split at every n-th splitter. </p> <p> When you set nth index to 0, nth_finder works exatly as the first_finder, so the sequence is split at every splitter. </p> <p> Best Regards, Pavol. </p> Ticket