Boost C++ Libraries: Ticket #6868: lex tokenize result error https://svn.boost.org/trac10/ticket/6868 <p> if uncomment the line #include &lt;boost/spirit/include/phoenix_statement.hpp&gt; the tokenize result is correct, why? </p> <p> the result is lines: 7, words: 0, characters: 155 </p> <p> the correct result is lines: 7, words: 33, characters: 162 </p> <p> visual studio 2010 </p> <pre class="wiki">// #define BOOST_SPIRIT_LEXERTL_DEBUG #include &lt;boost/config/warning_disable.hpp&gt; #include &lt;boost/spirit/include/lex_lexertl.hpp&gt; #include &lt;boost/spirit/include/phoenix_operator.hpp&gt; //if uncomment next line, the tokenize result is correct, why? //#include &lt;boost/spirit/include/phoenix_statement.hpp&gt; #include &lt;boost/spirit/include/phoenix_algorithm.hpp&gt; #include &lt;boost/spirit/include/phoenix_core.hpp&gt; #include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;string&gt; namespace lex = boost::spirit::lex; struct distance_func { template &lt;typename Iterator1, typename Iterator2&gt; struct result : boost::iterator_difference&lt;Iterator1&gt; {}; template &lt;typename Iterator1, typename Iterator2&gt; typename result&lt;Iterator1, Iterator2&gt;::type operator()(Iterator1&amp; begin, Iterator2&amp; end) const { return std::distance(begin, end); } }; boost::phoenix::function&lt;distance_func&gt; const distance1 = distance_func(); template &lt;typename Lexer&gt; struct word_count_tokens : lex::lexer&lt;Lexer&gt; { word_count_tokens() : c(0), w(0), l(0) , word("[^ \t\n]+") , eol("\n") , any(".") { using boost::spirit::lex::_start; using boost::spirit::lex::_end; using boost::phoenix::ref; this-&gt;self = word [++ref(w), ref(c) += distance1(_start, _end)] | eol [++ref(c), ++ref(l)] | any [++ref(c)] ; } std::size_t c, w, l; lex::token_def&lt;&gt; word, eol, any; }; int main(int argc, char* argv[]) { typedef lex::lexertl::token&lt;char const*, lex::omit, boost::mpl::false_&gt; token_type; typedef lex::lexertl::actor_lexer&lt;token_type&gt; lexer_type; word_count_tokens&lt;lexer_type&gt; word_count_lexer; std::string str ("Our hiking boots are ready. So, let's pack!\n\ \n\ Have you the plane tickets for there and back?\n\ \n\ I do, I do. We're all ready to go. Grab my hand and be my beau.\n\ \n\ \n"); char const* first = str.c_str(); char const* last = &amp;first[str.size()]; lexer_type::iterator_type iter = word_count_lexer.begin(first, last); lexer_type::iterator_type end = word_count_lexer.end(); while (iter != end &amp;&amp; token_is_valid(*iter)) ++iter; if (iter == end) { std::cout &lt;&lt; "lines: " &lt;&lt; word_count_lexer.l &lt;&lt; ", words: " &lt;&lt; word_count_lexer.w &lt;&lt; ", characters: " &lt;&lt; word_count_lexer.c &lt;&lt; "\n"; } else { std::string rest(first, last); std::cout &lt;&lt; "Lexical analysis failed\n" &lt;&lt; "stopped at: \"" &lt;&lt; rest &lt;&lt; "\"\n"; } return 0; } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6868 Trac 1.4.3 Nikita Kniazev <nok.raven@…> Thu, 14 Dec 2017 20:57:28 GMT <link>https://svn.boost.org/trac10/ticket/6868#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6868#comment:1</guid> <description> <p> I tried your example and it run fine (except <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6869" title="#6869: Bugs: spirit lex use phoenixV3 compile error (closed: fixed)">#6869</a>) and I have got <code>lines: 7, words: 33, characters: 178</code> in both cases. I'm sorry I'll not going to find the commit where it was fixed (it might was phoenix v2 problem). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joel de Guzman</dc:creator> <pubDate>Sun, 17 Dec 2017 23:44:15 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/6868#comment:2 https://svn.boost.org/trac10/ticket/6868#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">fixed</span> </li> </ul> Ticket