|
Boost : |
From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2003-07-31 02:58:06
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?
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?
Regards, Daniel
-- Daniel Frey aixigo AG - financial training, research and technology Schloß-Rahe-Straße 15, 52072 Aachen, Germany fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99 eMail: daniel.frey_at_[hidden], web: http://www.aixigo.de
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk