|
Boost : |
From: Daryle Walker (dwalker07_at_[hidden])
Date: 2003-08-01 02:44:28
On Thursday, July 31, 2003, at 9:58 AM, Daniel Frey wrote:
> Daryle Walker wrote:
>> In <boost/operators.hpp> we have helper classes that can generate
>> "operator OP" from "operator OP=", where "OP" can be "+", "/", ">>",
>> etc. What about types and algorithms where the non-assignment
>> version is easier than the assignment version? Should we have
>> reverse helpers?
>
> Sounds like a good idea in general. I think the naive implementation
> would be something like:
>
> T& operator OP##=( T& rhs, const U& lhs )
> {
> rhs = rhs OP lhs;
> return rhs;
> }
>
> OTOH I can think of a different solution:
>
> T& operator OP##=( T& rhs, const U& lhs )
> {
> T tmp( rhs OP lhs );
> using std::swap;
> swap( tmp, rhs );
> return rhs;
> }
>
> Which might be ways faster for certain classes. Which version were you
> thinking of? Which version offers a good balance in your opinion?
>
> What about the naming of the new classes? Do you have something in
> mind?
I just thought up the basic idea, but nothing like the formats and
such. You've gotten ahead of me.
> Do we need to prevent the user from deriving from both forms, creating
> infinite loops that only show up at run-time (+ calling += calling +
> calling += ...)? How shall we accomplish it without to much burden,
> possibly breaking the code for weaker compilers?
Wouldn't this only happen if the user explicitly coded it that way
(i.e. the user added the "OP from OP=" _and_ the "OP= from OP" helper
classes)?
Daryle
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk