www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11407] New: can't move struct with disabled default constructor

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

           Summary: can't move struct with disabled default constructor
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: code dawg.eu



cat > bug.d << CODE
import std.algorithm;

struct Unique
{
    int* _p;

     disable this(this);    // non-copyable
    ~this() { _p = null; }  // release resource
     disable this();        // non-null
    this(int* p) { _p = p; }// acquire resource
}

Unique bug(Unique u)
{
    return move(u);
}
CODE

dmd -c bug

----

The use-case is to encapsulate unique ownership in a struct.
It seems the static T empty; in move() is only need to reinitialized the moved
value. Maybe it could be done with destroy or by copying from
typeid(T).init().ptr.

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