Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For clarity - the error here is that <code>base_ &gt;&gt; int_ &gt;&gt; int_</code> was used as the expression for a rule that creates a <code>myderived</code>, and since <code>base_</code> is fixed to type <code>mybase</code>, we'd have to create a <code>myderrived</code> from a <code>mybase</code> and two <code>int</code>s, but there's nothing to tell Spirit how to do that.</p> <p>You can get boost to print out the type of the value that boost creates from parsing <code>base_ &gt;&gt; int_ &gt;&gt; int_</code> by defining a functor that will take any parameters, and tell you what they are (the following code is adapted from some code sehe put on SO chat): </p> <pre><code>struct what_is_the_attr { template &lt;typename&gt; struct result { typedef bool type; }; template &lt;typename T&gt; static void print_the_type() { std::cout &lt;&lt; " "; std::cout &lt;&lt; typeid(T).name(); if(std::is_const&lt;typename std::remove_reference&lt;T&gt;::type&gt;::value) std::cout &lt;&lt; " const"; if(std::is_rvalue_reference&lt;T&gt;::value) std::cout &lt;&lt; " &amp;&amp;"; else if(std::is_lvalue_reference&lt;T&gt;::value) std::cout &lt;&lt; " &amp;"; } template &lt;typename Th, typename Th2, typename... Tt&gt; static void print_the_type() { print_the_type&lt;Th&gt;(); std::cout &lt;&lt; ",\n"; print_the_type&lt;Th2, Tt...&gt;(); } template &lt;typename... Ts&gt; void operator()(Ts&amp;&amp;...) const { std::cout &lt;&lt; "what_is_the_attr(\n"; print_the_type&lt;Ts...&gt;(); std::cout &lt;&lt; ")" &lt;&lt; std::endl; } }; </code></pre> <p>Then to use it, use the above actor in a semantic action on initializer for your faulty rule:</p> <pre><code>std::string input = "1 2 3 4"; auto f(std::begin(input)), l(std::end(input)); rule&lt;decltype(f), mybase() , space_type&gt; base_ = int_ &gt;&gt; int_; rule&lt;decltype(f), myderived(), space_type&gt; derived_ = (base_ &gt;&gt; int_ &gt;&gt; int_)[what_is_the_attr()]; myderived data; bool ok = phrase_parse(f,l,derived_,space,data); </code></pre> <p><em>Note, you cannot use automatic attribute propagation with <code>%=</code> (unless you remove the exposed attribute type from the rule's declared type).</em></p> <p>Running this should then yield an encoded type, which can be decoded with <code>c++filt -t</code>: <strong><a href="http://coliru.stacked-crooked.com/a/4f5c90240b96d037" rel="nofollow">Live On Coliru</a></strong></p> <pre><code>$ g++ 9404189.cpp -std=c++0x $ ./a.out |c++filt -t what_is_the_attr( boost::fusion::vector3&lt;mybase, int, int&gt; &amp;, boost::spirit::context&lt;boost::fusion::cons&lt;boost::spirit::unused_type&amp;, boost::fusion::nil&gt;, boost::fusion::vector0&lt;void&gt; &gt; &amp;, bool &amp;) </code></pre> <p>The first line, <code>boost::fusion::vector3&lt;mybase, int, int&gt;</code>, least tells you that boost is trying to create your return type from 3 objects of types <code>mybase</code>, <code>int</code> and <code>int</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload