[Issue 11407] New: can't move struct with disabled default constructor

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Oct 31 22:37:32 PDT 2013


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 at puremagic.com
        ReportedBy: code at dawg.eu


--- Comment #0 from Martin Nowak <code at dawg.eu> 2013-10-31 22:37:31 PDT ---
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: -------


More information about the Digitalmars-d-bugs mailing list