Thread overview
[Issue 9164] New: Can't easily assign one Nullable to another
Dec 16, 2012
Artem Tarasov
Mar 03, 2013
Nick Sabalausky
Mar 03, 2013
Artem Tarasov
December 16, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9164

           Summary: Can't easily assign one Nullable to another
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: minor
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: lomereiter@gmail.com


--- Comment #0 from Artem Tarasov <lomereiter@gmail.com> 2012-12-16 02:49:05 PST ---
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;

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 17, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9164


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #1 from bearophile_hugs@eml.cc 2012-12-16 18:45:18 PST ---
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;
    }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 17, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9164



--- Comment #2 from bearophile_hugs@eml.cc 2012-12-16 18:46:52 PST ---
See also Issue 9166

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 03, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9164


Nick Sabalausky <cbkbbejeap@mailinator.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |cbkbbejeap@mailinator.com


--- Comment #3 from Nick Sabalausky <cbkbbejeap@mailinator.com> 2013-03-03 00:03:02 PST ---
This appears to be fixed as of 2.062.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 03, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9164


Artem Tarasov <lomereiter@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #4 from Artem Tarasov <lomereiter@gmail.com> 2013-03-03 00:11:59 PST ---
(In reply to comment #3)
> This appears to be fixed as of 2.062.

Indeed.

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