www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 808] New: using properties as lvalues

reply d-bugmail puremagic.com writes:

           Summary: using properties as lvalues
           Product: D
           Version: 0.178
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: enhancement
          Priority: P3
         Component: www.digitalmars.com
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: thecybershadow gmail.com

I've been wondering - what is actually preventing us to operate with properties
like real lvalues? For example,

int[] array;
array.length++;      // Error: (array).length is not an lvalue
array.length += 2;   // Error: (array).length is not an lvalue


array.length = array.length + 1; // works

Unless there's a fair reason of why this isn't viable, I'd suggest implementing

Jan 06 2007
next sibling parent d-bugmail puremagic.com writes:

------- Comment #1 from baryluk smp.if.uj.edu.pl  2009-04-02 08:49 -------
Assigment to properties is actually call to some method which actually do other
operations (like reallocation). I think that
   p op= x,
properties operations should be defined as
  p = p op x

Also for user defined properties (if both setter and getter is availble, so
"lvalue-like" behaviour can be emulated in this way). Cases in which p += x,
should be performed differently can always be emulated by using wrapper
struct/class, which caries state and overloads opAddAssign. This cases are
rear, but still possible. (usefull for some highly optimized codes, or
synchronized/atomic changes, or loging actuall changes)

array.length *= 2;  is one of the most annoying :)

Apr 02 2009
prev sibling parent d-bugmail puremagic.com writes:

dsimcha yahoo.com changed:

           What    |Removed                     |Added
                 CC|                            |ghaecker idworld.net

------- Comment #2 from dsimcha yahoo.com  2009-05-07 08:06 -------
*** Bug 2949 has been marked as a duplicate of this bug. ***

May 07 2009