Bug 8165 – BigInt opAssign return value

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-05-30T04:58:00Z
Last change time
2012-07-16T23:40:37Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2012-05-30T04:58:05Z
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; }
Comment #1 by clugdbug — 2012-07-16T23:39:10Z
*** Issue 7080 has been marked as a duplicate of this issue. ***
Comment #2 by clugdbug — 2012-07-16T23:40:37Z