array.length++ not an lvalue

Mike vertex at gmx.at
Wed Jun 18 09:25:47 PDT 2008


This could work if we had real properties. I'd really like to see an extended/modified version of the C# property syntax in D:

private int _length;
public property int length
{
    opSet() { return _length = value; }
    opGet() { return value; }
    opPostIncrement() { _length++; }
    // ...
}

That would solve the problem.

-Mike

Erik Lechak Wrote:

> Hello all,
> 
> I just wanted to start by thanking you for the great responses to my previous questions.  I appreciate the knowledgeable and friendly nature of this newsgroup.
> 
> I ran into my first WTF moment with D.  I spent way too much time figuring out why 'array'.length++ was a compiler error (Error: x.length is not an lvalue).
> 
> This is a newsgroup entry describing the problem: 
> http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=39179
> 
> Is there a document detailing these "special exceptions" so that I don't have to blindly stumble upon them?  If not are there any more that should be documented so that I can add them to my Wiki (http://www.lechak.info/wiki/index.php?title=D_Programming_Language)?  
> 
> For what it's worth, I think 'array'.length++ and 'array'.length += 1 should be valid.  If that is not an option, it would be nice if the error message could be changed to something like "Error: x.length is a special property that prohibits the use of the increment (++) and add_and_assign (+=) operators".  
> 
> Thanks,
> Erik Lechak
> 




More information about the Digitalmars-d mailing list