Summary: [TDPL] opAssign examples don't work as described
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD

--- Comment #0 from Trass3r <> 2012-02-16 02:34:20 CET ---
import std.algorithm;
struct Widget
    private int[] array;
    this(uint length)
        array = new int[length];

    this (this)
        array = array.dup;

    ref Widget opAssign(ref Widget rhs)
        array = rhs.array.dup;
        return this;
    ref Widget opAssign(Widget rhs)
        swap(array, rhs.array);
        return this;

void main()
    Widget w;
    w = Widget(50); // line 30

Two issues here:
1. Comment out the 2nd opAssign and the compiler should give an error, but it
(TDPL: // Cannot bind an rvalue of type Widget to ref Widget!)
2. TDPL's solution is 2 opAssigns, but this results in:

$ dmd -release -O -run test2.d 
test2.d(30): Error: overloads ref Widget(ref Widget rhs) and ref Widget(Widget
rhs) both match argument list for opAssign
test2.d(30): Error: function test2.Widget.opAssign called with argument types:
matches both:
    test2.Widget.opAssign(ref Widget rhs)
    test2.Widget.opAssign(Widget rhs)

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to