Boost C++ Libraries: Ticket #12085: (a - b) === (!b >> a) does not hold in X3 https://svn.boost.org/trac10/ticket/12085 <p> Following program checks that two grammars (GRAMMAR1 and GRAMMAR2) are giving the same result for x3 and qi. They don't. </p> <p> GRAMMAR1 is (!b &gt;&gt; a), GRAMMAR2 is (a - b). </p> <p> When x3 is used (USE_X3==1) output is: </p> <p> 1 d<br /> 1 abcd<br /> </p> <p> When qi is used (USE_X3==0) output is: </p> <p> 1 abcd<br /> 1 abcd<br /> </p> <pre class="wiki">#define USE_X3 1 #if USE_X3 == 1 #include &lt;boost/spirit/home/x3.hpp&gt; #else #include &lt;boost/spirit/include/qi.hpp&gt; #endif #include &lt;iostream&gt; #include &lt;string&gt; #include &lt;vector&gt; #define GRAMMAR1 !lexeme[keywords &gt;&gt; !(alnum | '_')] &gt;&gt; lexeme[(alpha | '_') &gt;&gt; *(alnum | '_')] #define GRAMMAR2 lexeme[(alpha | '_') &gt;&gt; *(alnum | '_')] - lexeme[keywords &gt;&gt; !(alnum | '_')] int main() { std::string str = "abcd"; auto end = str.end(); #if USE_X3 == 1 { using namespace boost::spirit::x3; symbols&lt;&gt; keywords({"k1", "k2", "k3"}); { std::string v; auto begin = str.begin(); bool full = boost::spirit::x3::parse(begin, end, GRAMMAR1, v) &amp;&amp; begin == end; std::cout &lt;&lt; full &lt;&lt; " " &lt;&lt; v &lt;&lt; std::endl; } { std::string v; auto begin = str.begin(); bool full = boost::spirit::x3::parse(begin, end, GRAMMAR2, v) &amp;&amp; begin == end; std::cout &lt;&lt; full &lt;&lt; " " &lt;&lt; v &lt;&lt; std::endl; } } #else { using namespace boost::spirit::qi; symbols&lt;&gt; keywords; keywords = "k1", "k2", "k3"; { std::string v; auto begin = str.begin(); bool full = boost::spirit::qi::parse(begin, end, GRAMMAR1, v) &amp;&amp; begin == end; std::cout &lt;&lt; full &lt;&lt; " " &lt;&lt; v &lt;&lt; std::endl; } { std::string v; auto begin = str.begin(); bool full = boost::spirit::qi::parse(begin, end, GRAMMAR2, v) &amp;&amp; begin == end; std::cout &lt;&lt; full &lt;&lt; " " &lt;&lt; v &lt;&lt; std::endl; } } #endif } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12085 Trac 1.4.3 Joel de Guzman Sun, 27 Mar 2016 10:49:42 GMT <link>https://svn.boost.org/trac10/ticket/12085#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12085#comment:1</guid> <description> <p> Is this a TST issue? </p> </description> <category>Ticket</category> </item> <item> <author>mikhail.strelnikov@…</author> <pubDate>Sun, 27 Mar 2016 13:46:21 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12085#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12085#comment:2</guid> <description> <p> Yes. What do you think about <a class="ext-link" href="https://github.com/boostorg/spirit/pull/181/commits/1f6d6c61849e89527c9b7be0818a16ce4833e8cf"><span class="icon">​</span>https://github.com/boostorg/spirit/pull/181/commits/1f6d6c61849e89527c9b7be0818a16ce4833e8cf</a> ? Should this work in x3 or should it not in qi? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joel de Guzman</dc:creator> <pubDate>Sun, 27 Mar 2016 22:22:56 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12085#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12085#comment:3</guid> <description> <p> I'm not sure. I still need to investigate. That said, if this one is a TST issue, then the test should be minimized further. It will be confusing to conflate the TST issue and the (!b &gt;&gt; a) and (a - b) issue together. </p> </description> <category>Ticket</category> </item> <item> <author>mikhail.strelnikov@…</author> <pubDate>Mon, 28 Mar 2016 16:48:08 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12085#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12085#comment:4</guid> <description> <p> I think all this can be minimized to - </p> <pre class="wiki">static_assert(traits::is_substitute&lt;fusion::deque&lt;char, std::string&gt;, std::string&gt;::value == 1, ""); </pre><p> or even simpler </p> <pre class="wiki">static_assert(traits::is_substitute&lt;char, std::string&gt;::value == 1, ""); </pre><p> Which is kind of makes sense - if we have a char, we can put it to a string. </p> <p> If this compiles, then test passes. I've tried this by adding specialization </p> <pre class="wiki">template &lt;typename T, typename Attribute&gt; struct is_substitute&lt;T, Attribute, typename enable_if&lt;is_container&lt;Attribute&gt; &gt;::type&gt; : is_substitute&lt;typename mpl::eval_if &lt; fusion::traits::is_sequence&lt;T&gt;, fusion::result_of::front&lt;T&gt;, mpl::identity&lt;T&gt; &gt;::type, typename container_value&lt;Attribute&gt;::type&gt; {}; </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Joel de Guzman</dc:creator> <pubDate>Mon, 28 Mar 2016 22:29:41 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12085#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12085#comment:5</guid> <description> <p> So it's not a TST issue then. An is_substitute specialization would be easy to add. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joel de Guzman</dc:creator> <pubDate>Mon, 28 Mar 2016 22:31:29 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12085#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12085#comment:6</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/12085#comment:5" title="Comment 5">djowel</a>: </p> <blockquote class="citation"> <p> So it's not a TST issue then. An is_substitute specialization would be easy to add. Does your specialization compile? Seems too complicated. </p> </blockquote> </description> <category>Ticket</category> </item> <item> <author>Nikita Kniazev <nok.raven@…></author> <pubDate>Sun, 25 Feb 2018 01:12:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12085#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12085#comment:7</guid> <description> <p> I think have a good fix <a class="ext-link" href="https://github.com/boostorg/spirit/pull/370"><span class="icon">​</span>https://github.com/boostorg/spirit/pull/370</a> </p> </description> <category>Ticket</category> </item> <item> <author>Nikita Kniazev <nok.raven@…></author> <pubDate>Thu, 01 Mar 2018 10:45:53 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12085#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12085#comment:8</guid> <description> <p> Fixed in ​<a class="ext-link" href="https://github.com/boostorg/spirit/pull/370"><span class="icon">​</span>https://github.com/boostorg/spirit/pull/370</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joel de Guzman</dc:creator> <pubDate>Thu, 15 Mar 2018 22:58:57 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/12085#comment:9 https://svn.boost.org/trac10/ticket/12085#comment:9 <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