Opened 14 years ago

Closed 14 years ago

#2938 closed Bugs (invalid)

[operators] BOOST_OPERATOR2_LEFT prevents builtin types from being used as first template parameter

Reported by: Arne Mertz <boost@…> Owned by: Daniel Frey
Milestone: Boost 1.39.0 Component: operators
Version: Boost 1.38.0 Severity: Problem
Keywords: Cc:

Description

Minimal code example:

#include <boost/operators.hpp>

class X : public boost::subtractable2_left<double, X> { public:

friend double& operator-= (double& lhs, X const&) { return lhs; }

operator double() const {return 1.0;}

};

int main() {

X x; double d = x - 0.5; ERROR: left operand of op-= has to be l-value

}

#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.

Change History (1)

comment:1 by Daniel Frey, 14 years ago

Resolution: invalid
Status: newclosed

I assume that by BOOST_NO_NRVO you mean BOOST_HAS_HRVO. First question: Does setting BOOST_FORCE_SYMMETRIC_OPERATORS solves your problem?

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:

"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<T, U>. "

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.

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.

Note: See TracTickets for help on using tickets.