Boost C++ Libraries: Ticket #6043: Spirit insists that user types are adapted to Fusion https://svn.boost.org/trac10/ticket/6043 <p> I've played with Spirit for the first time, and arrived at the attached example. Basically, I want to create Foo instances from pairs of numbers. This example does not compile unless Foo is adapted to fusion. I don't think this is a good idea, because from the point of view of user, the parser should create instances of Foo, and it's not really clear why parser should iterate over existing instances -- which is what it is trying to do. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6043 Trac 1.4.3 Vladimir Prus Thu, 20 Oct 2011 16:41:28 GMT attachment set https://svn.boost.org/trac10/ticket/6043 https://svn.boost.org/trac10/ticket/6043 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">main.cpp</span> </li> </ul> <p> testcase </p> Ticket Vladimir Prus Thu, 20 Oct 2011 16:44:39 GMT <link>https://svn.boost.org/trac10/ticket/6043#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6043#comment:1</guid> <description> <p> On IRC, Thomas produced somewhat easier example. Code the does not work: </p> <pre class="wiki">#include &lt;boost/spirit/home/qi.hpp&gt; #include &lt;boost/spirit/home/phoenix.hpp&gt; namespace fusion = boost::fusion; namespace qi = boost::spirit::qi; namespace phoenix = boost::phoenix; struct foo { foo(fusion::vector&lt;int, double&gt;) {} }; int main() { typedef std::string::iterator iterator; qi::rule&lt;iterator, foo()&gt; foo_rule; foo_rule = (qi::int_ &gt;&gt; qi::double_); } </pre><p> Code that does work: </p> <pre class="wiki">#include &lt;boost/spirit/home/qi.hpp&gt; #include &lt;boost/spirit/home/phoenix.hpp&gt; namespace fusion = boost::fusion; namespace qi = boost::spirit::qi; namespace phoenix = boost::phoenix; struct foo { foo() {} foo(int, double) {} foo(fusion::vector&lt;int, double&gt;) {} }; int main() { typedef std::string::iterator iterator; qi::rule&lt;iterator, fusion::vector&lt;int, double&gt;()&gt; tuple_rule; qi::rule&lt;iterator, foo()&gt; foo_rule; tuple_rule = (qi::int_ &gt;&gt; qi::double_); foo_rule %= tuple_rule.alias(); } </pre><p> I frankly don't understand what's going on here, but trying the same workaround for me does not work (with Boost trunk, and gcc 4.5.3), while Thomas reported this new example (main-with-workaround.cpp) compiles for him just fine with 1.47. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Vladimir Prus</dc:creator> <pubDate>Thu, 20 Oct 2011 16:45:17 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/6043 https://svn.boost.org/trac10/ticket/6043 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">main-with-workaround.cpp</span> </li> </ul> <p> testcase with attempted workaround, still does not work for me. </p> Ticket anonymous Tue, 08 Nov 2011 16:02:34 GMT component changed; owner set https://svn.boost.org/trac10/ticket/6043#comment:2 https://svn.boost.org/trac10/ticket/6043#comment:2 <ul> <li><strong>owner</strong> set to <span class="trac-author">Joel de Guzman</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">spirit</span> </li> </ul> Ticket anonymous Wed, 09 Nov 2011 00:16:14 GMT <link>https://svn.boost.org/trac10/ticket/6043#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6043#comment:3</guid> <description> <p> Here's what's happening: </p> <p> When you have A &gt;&gt; B, the rules are: <a class="ext-link" href="http://tinyurl.com/bqch2m6"><span class="icon">​</span>http://tinyurl.com/bqch2m6</a> </p> <p> So, as far as compatibility goes, the attribute either has to be a fusion sequence *or* a std container. That is why your code does not compile. </p> <p> The thing is, spirit is optimal and walks the sequence and builds its elements in-situ, instead of synthesising a temporary sequence in memory and assign later. That is why it has to iterate over existing instances. In this case, it cannot walk a foo. Heller's workaround works because the inner rule is able to walk the fusion sequence and then attribute transformation kicks in whereby it assigns the fusion sequence to foo. That works but is sub optimal. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joel de Guzman</dc:creator> <pubDate>Wed, 09 Nov 2011 23:43:29 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/6043#comment:4 https://svn.boost.org/trac10/ticket/6043#comment:4 <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">wontfix</span> </li> </ul> <p> Volodya, I'm going to close this as no-fix. If you want to discuss, we can do it in IRC or the mailing lists. </p> Ticket