Chad J Wrote:
> Currently there are some cases where the current paradigm forces you to
> do that kind of work by hand:
>
> struct Rectangle
> {
> float x,y,w,h;
> }
> class Widget
> {
> Rectangle _rect;
> Rectangle rect() { return _rect; }
> Rectangle rect(Rectangle r) { return _rect = r; }
> }
> void main()
> {
> auto widget = new Widget();
>
> // DOES WORK:
> auto tmp = widget.rect;
> tmp.w = 200;
> tmp.h = 100;
> widget.rect = tmp;
>
> // DOES NOT WORK:
> // widget.rect.w = 200;
> // widget.rect.h = 100;
> }
What about:
class Widget
{
Rectangle _rect;
immutable(Rectangle) rect() const { return _rect; }
Rectangle rect(Rectangle r) { return _rect = r; }
}