http://d.puremagic.com/issues/show_bug.cgi?id=8165

           Summary: BigInt opAssign return value
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nob...@puremagic.com
        ReportedBy: bearophile_h...@eml.cc


--- Comment #0 from bearophile_h...@eml.cc 2012-05-30 04:58:05 PDT ---
This code is allowed, it's handy when you have to initialize two array items:

void main() {
    int[2] a;
    a[0] = a[1] = 1;
}


So I'd like to do:

import std.bigint: BigInt;
void main() {
    BigInt[2] a;
    a[0] = 1; // OK
    a[0] = a[1] = 1; // error
}


DMD 2.060alpha gives:

test.d(5): Error: template std.bigint.BigInt.opAssign does not match any
function template declaration
...\dmd2\src\phobos\std\bigint.d(115): Error: template
std.bigint.BigInt.opAssign cannot deduce template function from argument types
!()(void)


I think to solve this problem it's enough to modify the two functions:
    ///
    void opAssign(T: long)(T x)
    {
        data = cast(ulong)((x < 0) ? -x : x);
        sign = (x < 0);
    }

    ///
    void opAssign(T:BigInt)(T x)
    {
        data = x.data;
        sign = x.sign;
    }


Like this:

    ///
    BigInt opAssign(T: long)(T x)
    {
        data = cast(ulong)((x < 0) ? -x : x);
        sign = (x < 0);
        return this;
    }

    ///
    BigInt opAssign(T:BigInt)(T x)
    {
        data = x.data;
        sign = x.sign;
        return x;
    }

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

Reply via email to