Boost C++ Libraries: Ticket #6869: spirit lex use phoenixV3 compile error https://svn.boost.org/trac10/ticket/6869 <p> if #define BOOST_SPIRIT_USE_PHOENIX_V3 1 this code can't be compile error </p> <pre class="wiki">// #define BOOST_SPIRIT_LEXERTL_DEBUG #define BOOST_SPIRIT_USE_PHOENIX_V3 1 #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; #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/6869 Trac 1.4.3 anonymous Sun, 06 May 2012 05:56:34 GMT <link>https://svn.boost.org/trac10/ticket/6869#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6869#comment:1</guid> <description> <p> the compiler is vc10 </p> </description> <category>Ticket</category> </item> <item> <author>Nikita Kniazev <nok.raven@…></author> <pubDate>Tue, 05 Dec 2017 19:28:08 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6869#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6869#comment:2</guid> <description> <p> The Spirit examples wrongly uses <code>result_of</code> protocol. I am working on fixing examples, but it is still WIP. To fix your problem, you should fix <code>distance_func</code> like this: </p> <div class="wiki-code"><div class="code"><pre><span class="k">struct</span> <span class="n">distance_func</span> <span class="p">{</span> <span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">Sig</span><span class="o">&gt;</span> <span class="k">struct</span> <span class="n">result</span><span class="p">;</span> <span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">F</span><span class="p">,</span> <span class="k">typename</span> <span class="n">Iterator1</span><span class="p">,</span> <span class="k">typename</span> <span class="n">Iterator2</span><span class="o">&gt;</span> <span class="k">struct</span> <span class="n">result</span><span class="o">&lt;</span><span class="n">F</span><span class="p">(</span><span class="n">Iterator1</span> <span class="k">const</span><span class="o">&amp;</span><span class="p">,</span> <span class="n">Iterator2</span> <span class="k">const</span><span class="o">&amp;</span><span class="p">)</span><span class="o">&gt;</span> <span class="o">:</span> <span class="n">boost</span><span class="o">::</span><span class="n">iterator_difference</span><span class="o">&lt;</span><span class="n">Iterator1</span><span class="o">&gt;</span> <span class="p">{};</span> <span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">F</span><span class="p">,</span> <span class="k">typename</span> <span class="n">Iterator1</span><span class="p">,</span> <span class="k">typename</span> <span class="n">Iterator2</span><span class="o">&gt;</span> <span class="k">struct</span> <span class="n">result</span><span class="o">&lt;</span><span class="n">F</span><span class="p">(</span><span class="n">Iterator1</span><span class="o">&amp;</span><span class="p">,</span> <span class="n">Iterator2</span><span class="o">&amp;</span><span class="p">)</span><span class="o">&gt;</span> <span class="o">:</span> <span class="n">result</span><span class="o">&lt;</span><span class="n">F</span><span class="p">(</span><span class="n">Iterator1</span> <span class="k">const</span><span class="o">&amp;</span><span class="p">,</span> <span class="n">Iterator2</span> <span class="k">const</span><span class="o">&amp;</span><span class="p">)</span><span class="o">&gt;</span> <span class="p">{};</span> <span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">Iterator1</span><span class="p">,</span> <span class="k">typename</span> <span class="n">Iterator2</span><span class="o">&gt;</span> <span class="k">typename</span> <span class="n">result</span><span class="o">&lt;</span><span class="n">distance_func</span><span class="p">(</span><span class="n">Iterator1</span><span class="o">&amp;</span><span class="p">,</span> <span class="n">Iterator2</span><span class="o">&amp;</span><span class="p">)</span><span class="o">&gt;::</span><span class="n">type</span> <span class="k">operator</span><span class="p">()(</span><span class="n">Iterator1</span><span class="o">&amp;</span> <span class="n">begin</span><span class="p">,</span> <span class="n">Iterator2</span><span class="o">&amp;</span> <span class="n">end</span><span class="p">)</span> <span class="k">const</span> <span class="p">{</span> <span class="k">return</span> <span class="n">std</span><span class="o">::</span><span class="n">distance</span><span class="p">(</span><span class="n">begin</span><span class="p">,</span> <span class="n">end</span><span class="p">);</span> <span class="p">}</span> <span class="p">};</span> </pre></div></div><p> Or it could be a little simpler (<code>std::distance</code> requires both iterators to have the same type): </p> <div class="wiki-code"><div class="code"><pre><span class="k">struct</span> <span class="n">distance_func</span> <span class="p">{</span> <span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span><span class="o">&gt;</span> <span class="k">struct</span> <span class="n">result</span><span class="p">;</span> <span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">F</span><span class="p">,</span> <span class="k">typename</span> <span class="n">Iterator</span><span class="o">&gt;</span> <span class="k">struct</span> <span class="n">result</span><span class="o">&lt;</span><span class="n">F</span><span class="p">(</span><span class="n">Iterator</span><span class="p">,</span> <span class="n">Iterator</span><span class="p">)</span><span class="o">&gt;</span> <span class="o">:</span> <span class="n">boost</span><span class="o">::</span><span class="n">iterator_difference</span><span class="o">&lt;</span><span class="k">typename</span> <span class="n">boost</span><span class="o">::</span><span class="n">decay</span><span class="o">&lt;</span><span class="n">Iterator</span><span class="o">&gt;::</span><span class="n">type</span><span class="o">&gt;</span> <span class="p">{};</span> <span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">Iterator</span><span class="o">&gt;</span> <span class="k">typename</span> <span class="n">result</span><span class="o">&lt;</span><span class="n">distance_func</span><span class="p">(</span><span class="n">Iterator</span><span class="o">&amp;</span><span class="p">,</span> <span class="n">Iterator</span><span class="o">&amp;</span><span class="p">)</span><span class="o">&gt;::</span><span class="n">type</span> <span class="k">operator</span><span class="p">()(</span><span class="n">Iterator</span><span class="o">&amp;</span> <span class="n">begin</span><span class="p">,</span> <span class="n">Iterator</span><span class="o">&amp;</span> <span class="n">end</span><span class="p">)</span> <span class="k">const</span> <span class="p">{</span> <span class="k">return</span> <span class="n">std</span><span class="o">::</span><span class="n">distance</span><span class="p">(</span><span class="n">begin</span><span class="p">,</span> <span class="n">end</span><span class="p">);</span> <span class="p">}</span> <span class="p">};</span> </pre></div></div> </description> <category>Ticket</category> </item> <item> <dc:creator>Joel de Guzman</dc:creator> <pubDate>Wed, 13 Dec 2017 23:07:43 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/6869#comment:3 https://svn.boost.org/trac10/ticket/6869#comment:3 <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