www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5044] New: opIndexUnary not working for post++

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5044

           Summary: opIndexUnary not working for post++
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: ah08010-d yahoo.com


--- Comment #0 from Austin Hastings <ah08010-d yahoo.com> 2010-10-11 17:44:11
PDT ---
This code:
==========
module scratch;

class C( element_t ) {

    element_t [] contents;

    element_t opIndex( int index ) {
        return contents[ index ];
    }

    element_t opIndexUnary( string op )( int index ) {

        static if( op == "++" ) {
            return ++contents[ index ];
        }
        else {
            static assert( false );
        }
    }

}

unittest {
    auto c = new C!int();

    c[0]++;
}
==========
Produces this output:
==========
$ dmd -c -unittest scratch.d
scratch.d(42): Error: c.opIndex(0) is not an lvalue
==========
But if the penultimate line: "c[0]++" is replaced by "++c[0]", there is no
problem.

And finally, if the opIndex is changed to return a 'ref', there is not problem,
but the opIndexUnary operator is not called - the reference is incremented as
an int, I think.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 11 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5044


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
                 CC|                            |clugdbug yahoo.com.au
           Severity|normal                      |major


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 17 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5044


monarchdodra gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh quickfur.ath.cx


--- Comment #1 from monarchdodra gmail.com 2012-07-26 01:28:56 PDT ---
*** Issue 7733 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 26 2012