Bug 9164 – Can't easily assign one Nullable to another

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-12-16T02:49:00Z
Last change time
2013-03-03T00:11:59Z
Assigned to
nobody
Creator
lomereiter

Comments

Comment #0 by lomereiter — 2012-12-16T02:49:05Z
Example: import std.typecons; void main() { Nullable!int a, b; a = b; // what seems to happen is a.opAssign(b.get) => enforcement fails } The workaround is simple but ugly: if (b.isNull) a.nullify(); else a = b;
Comment #1 by bearophile_hugs — 2012-12-16T18:45:18Z
Adding an opAssign overload to Nullable is maybe enough: /** Assigns $(D value) to the internally-held state. If the assignment succeeds, $(D this) becomes non-null. */ void opAssign()(T value) { _value = value; _isNull = false; } /// ditto void opAssign()(Nullable other) { _value = other._value; _isNull = other._isNull; } Or maybe just (no templated): /** Assigns $(D value) to the internally-held state. If the assignment succeeds, $(D this) becomes non-null. */ void opAssign(T value) { _value = value; _isNull = false; } /// ditto void opAssign(Nullable other) { _value = other._value; _isNull = other._isNull; }
Comment #2 by bearophile_hugs — 2012-12-16T18:46:52Z
See also Issue 9166
Comment #3 by bus_dbugzilla — 2013-03-03T00:03:02Z
This appears to be fixed as of 2.062.
Comment #4 by lomereiter — 2013-03-03T00:11:59Z
(In reply to comment #3) > This appears to be fixed as of 2.062. Indeed.