Operator overhaul
Christian Kamm
kamm-incasoftware at removethis.de
Tue Oct 21 23:02:21 PDT 2008
Andrei Alexandrescu wrote:
> I'll tell you what is, to me, clearly dead
> wrong: whenever one implements any class that wants to overload a bunch
> of operators (number-like classes etc.) inevitably it boils down to
> repetitive code like this:
>
> struct Whatever
> {
> Whatever opAdd(Whatever rhs) { return member + rhs.member; }
> Whatever opSubtract(Whatever rhs) { return member - rhs.member; }
> ...
> }
>
> and lines and lines of brain damaged repetition, repetition, repetition.
> If we add opWhateverAssign that will get even worse. The challenge is,
> then, to define a way to overload operators that makes the classic
> applications of the feature short and sweet.
Maybe that could be done similarly to boost.operators
(http://www.boost.org/doc/libs/1_36_0/libs/utility/operators.htm), only
using template mixins?
The main problem I see with any solution is that it will need to be pretty
complicated to accomodate for all cases and be generally useful. In the
end, understanding what the mixins do exactly may take longer than having a
set of repetitive, but trivial overloads.
More information about the Digitalmars-d
mailing list