division of objects into classes and structures is bad

Christopher Wright dhasenan at gmail.com
Tue Dec 30 06:42:46 PST 2008


Don wrote:
> The creation of temporaries during expressions is something I'm 
> currently working on solving. The case you mentioned is addressed by a 
> proposal I made long ago:

The easiest way is to add an intermediate struct. This takes a fair bit 
of manual effort, though, and prevents you from using auto.

Essentially, you need a struct MyClassAddition that just records 
operands. Then give it an implicit cast to MyClass that does the work. 
This is an ugly solution because you need to duplicate the operator 
overloads on MyClassXXX as well as MyClass.

I believe I got this solution from an article by Andrei. It should work 
pretty well for classes that define few overloads.



More information about the Digitalmars-d mailing list