Boost C++ Libraries: Ticket #10811: Add operators !=, <=, >, >= https://svn.boost.org/trac10/ticket/10811 <p> These operators are missing. It should be great if they are defined in function of the corresponding operators on the corresponding types. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10811 Trac 1.4.3 Antony Polukhin Wed, 03 Dec 2014 17:44:23 GMT owner, status, milestone changed https://svn.boost.org/trac10/ticket/10811#comment:1 https://svn.boost.org/trac10/ticket/10811#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">ebf</span> to <span class="trac-author">Antony Polukhin</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.58.0</span> </li> </ul> <p> Added missing operator to <a class="ext-link" href="https://github.com/boostorg/variant/commit/6db941f3ddc77851e3ce3f596b0273a72e440509"><span class="icon">​</span>the develop branch</a>. </p> Ticket gast128@… Wed, 03 Dec 2014 19:34:41 GMT <link>https://svn.boost.org/trac10/ticket/10811#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10811#comment:2</guid> <description> <p> Isn't this the same as <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8620" title="#8620: Feature Requests: Boost.Variant has no inequality operator (closed: fixed)">#8620</a>? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Wed, 03 Dec 2014 22:12:40 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10811#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10811#comment:3</guid> <description> <p> Thanks even if I expected that operator&gt;= be defined in terms of operator&gt;= :( </p> <p> I find weird making private these kind of overloads. </p> <pre class="wiki"> inline bool operator&gt;=(const variant&amp; rhs) const { return !(*this &lt; rhs); } </pre><p> Does it means that </p> <pre class="wiki">variant&lt; int, string&gt; v = 1; auto x = 1 &lt; v; </pre><p> would compile and </p> <pre class="wiki">variant&lt; int, string&gt; v = 1; auto x = v &lt; 1; </pre><p> wouldn't? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Antony Polukhin</dc:creator> <pubDate>Thu, 04 Dec 2014 10:30:54 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10811#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10811#comment:4</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/10811#comment:2" title="Comment 2">gast128@…</a>: </p> <blockquote class="citation"> <p> Isn't this the same as <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8620" title="#8620: Feature Requests: Boost.Variant has no inequality operator (closed: fixed)">#8620</a>? </p> </blockquote> <p> This ticket is more generic, <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8620" title="#8620: Feature Requests: Boost.Variant has no inequality operator (closed: fixed)">#8620</a> requests only <code>operator!=()</code>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Antony Polukhin</dc:creator> <pubDate>Thu, 04 Dec 2014 10:59:36 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10811#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10811#comment:5</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/10811#comment:3" title="Comment 3">viboes</a>: </p> <blockquote class="citation"> <p> Thanks even if I expected that operator&gt;= be defined in terms of operator&gt;= :( </p> </blockquote> <p> Current approach reduces binary size. It also follows the Standard Library approach (for example <code>std::vector</code> implement comparisons in the same way) to reduce requirements for <a class="missing wiki">ValueTypes</a>. <br /> <br /> </p> <blockquote class="citation"> <p> I find weird making private these kind of overloads. </p> <pre class="wiki"> inline bool operator&gt;=(const variant&amp; rhs) const { return !(*this &lt; rhs); } </pre><p> Does it means that </p> <pre class="wiki">variant&lt; int, string&gt; v = 1; auto x = 1 &lt; v; </pre><p> would compile and </p> <pre class="wiki">variant&lt; int, string&gt; v = 1; auto x = v &lt; 1; </pre><p> wouldn't? </p> </blockquote> <p> Both cases won't compile. I was following the existing schema and implemented those operators in the same way as <code>operator==</code> and <code>operator&lt;</code> were implemented. </p> <p> Though it could be useful to have comparison operators with types that are held in variant, just like in your example: <code>(1 &lt; v || v &lt; 1)</code>. To do it in an effective way some metaprograming pretty close to one required by <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/547" title="#547: Feature Requests: [variant] Compile time checked getter (closed: fixed)">#547</a> must be done. Created a separate ticket <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/10845" title="#10845: Feature Requests: Generic comparison operators (closed: duplicate)">#10845</a> for this feature. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Thu, 04 Dec 2014 17:54:50 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10811#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10811#comment:6</guid> <description> <p> Sorry I meant </p> <pre class="wiki">template &lt;typename U&gt; void operator&gt;=(const U&amp;) const { BOOST_STATIC_ASSERT( false &amp;&amp; sizeof(U) ); } </pre><p> Why have you added this assertion so that the </p> <pre class="wiki">auto x = v &lt; 1; </pre><p> doesn't compiles and the you add another ticket to allow it? </p> <p> Am I missing something? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Antony Polukhin</dc:creator> <pubDate>Fri, 05 Dec 2014 08:57:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10811#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10811#comment:7</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/10811#comment:6" title="Comment 6">viboes</a>: </p> <blockquote class="citation"> <p> Am I missing something? </p> </blockquote> <p> Current implementation forbids such conversions because they could be very ineffective: </p> <pre class="wiki">variant&lt;int, std::sting&gt; v(1); // implicit construction of variant with a string in it auto res = (v != "How you doin'? - (C) Joey"); </pre><p> Such approach was used long time ago for variant::operator== and variant::operator&lt;. </p> <p> Why separate ticket? Because: </p> <ul><li>I'm not sure that such comparisons could be implemented using C++03 in an efficient way, they could be enabled as an extension that requires C++11/C++14. There are some chances that <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/10845" title="#10845: Feature Requests: Generic comparison operators (closed: duplicate)">#10845</a> will be resolved as 'wontfix', because of compiler limitations or some other issues. </li><li>Current implementation of comparison operators will remain (at least partially) even if the new one will be added </li><li>This ticket will be fixed in Boost 1.58. New comparison operators could take some time to implement and I'm not sure that they will make their way into Boost 1.58. My memory is lame and that's why some reminder (ticket) is added to trac to not forget about cool feature to implement :) </li></ul> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Fri, 05 Dec 2014 18:17:20 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10811#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10811#comment:8</guid> <description> <p> std::experimental optional defines comparison between optional&lt;T&gt; and T so that it can be done more efficiently. What is wrong with this? </p> <p> I would prefer to have a good c++11 interface that don't have one at all. </p> <p> A std::less&lt;variant&lt;Args...&gt;&gt; specialization in function of std::less&lt;Args&gt;... is necessary in the cases where one of the Args don't defines operator &lt;, but has the std::less specialization. I could create a new ticket for this, if you agree. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Antony Polukhin</dc:creator> <pubDate>Mon, 09 Mar 2015 11:52:39 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/10811#comment:9 https://svn.boost.org/trac10/ticket/10811#comment:9 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket