Boost C++ Libraries: Ticket #2938: [operators] BOOST_OPERATOR2_LEFT prevents builtin types from being used as first template parameter https://svn.boost.org/trac10/ticket/2938 <p> Minimal code example: </p> <p> #include &lt;boost/operators.hpp&gt; </p> <p> class X : public boost::subtractable2_left&lt;double, X&gt; { public: </p> <blockquote> <p> friend double&amp; operator-= (double&amp; lhs, X const&amp;) { return lhs; } </p> </blockquote> <blockquote> <p> operator double() const {return 1.0;} </p> </blockquote> <p> }; </p> <p> int main() { </p> <blockquote> <p> X x; double d = x - 0.5; <em>ERROR: left operand of op-= has to be l-value </em></p> </blockquote> <p> } </p> <p> #defines BOOST_NO_NRVO and BOOST_FORCE_SYMMETRIC_OPERATORS are not set, so the short implementation in line 240 (as of Sat April 4th, 2009) is used: return T( lhs ) -= rhs; on msvc 2008 express this does not work with T being a builtin type. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2938 Trac 1.4.3 Daniel Frey Sat, 18 Apr 2009 09:10:02 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2938#comment:1 https://svn.boost.org/trac10/ticket/2938#comment:1 <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">invalid</span> </li> </ul> <p> I assume that by BOOST_NO_NRVO you mean BOOST_HAS_HRVO. First question: Does setting BOOST_FORCE_SYMMETRIC_OPERATORS solves your problem? </p> <p> The documentation is not too clear on builtin types, but the "usual" use-case is, that the first parameter of the operator templates is a UDT. From the docs: </p> <p> "When applying the two-argument form of a template, the desired return type of the operators typically determines which of the two types in question should be derived from the operator template. For example, if the result of T + U is of type T, then T (not U) should be derived from addable&lt;T, U&gt;. " </p> <p> Of course there is "typically" and "should" in there and the requirement tables later in the docs only says "temp" but doesn't exactly say that "temp" could be a temporary. In fact, it leaves the impression that "temp" is always from an expression like "T temp(u)" which makes it a normal variable, not a real temporary. </p> <p> I added a note to the docs to point out that the type T (the first template argument) may not be a builtin type and I'll close this ticket. If you don't agree (and if setting BOOST_FORCE_SYMMETRIC_OPERATORS doesn't work for you or is not a satisfying solution), feel free to ask on the boost-devel list so we can discuss if and how builtin types could be supported. </p> Ticket