Skip to content

Commit

Permalink
Support DMD for vector moves
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaTheFoxgirl committed Apr 9, 2024
1 parent 84541d6 commit 3d33e04
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
21 changes: 20 additions & 1 deletion source/numem/mem/ptr.d
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,29 @@ public:
// atomically moves the reference from this unique_ptr to the other unique_ptr reference
// after this is done, rc is set to null to make this unique_ptr invalid.
atomicStore(this.rc, other.rc);
this.rc = other.rc;
other.clear();
}

/**
Moves unique_ptr to this instance.
This is a reuse of copy-constructors, and is unique to unique_ptr.
This exists for DMD support.
*/
this(ref const(unique_ptr!T) other) {

// Free our own refcount if need be
if (this.rc) {
this.reset();
}

// atomically moves the reference from this unique_ptr to the other unique_ptr reference
// after this is done, rc is set to null to make this unique_ptr invalid.
atomicStore(this.rc, cast(refcountmg_t!(T)*)other.rc);
atomicStore(other.rc, null);
}

// Destructor
~this() {

Expand Down
4 changes: 2 additions & 2 deletions source/numem/mem/vector.d
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public:
/**
Moves non-copyable members of one vector to another
*/
this(ref return scope vector!T rhs) {
this(ref vector!T rhs) {
if (rhs.memory) {
this.resize_(rhs.size_);
foreach(i; 0..rhs.size_) {
Expand All @@ -125,7 +125,7 @@ public:
/**
Makes a copy of a vector
*/
this(ref return scope vector!T rhs) {
this(ref vector!T rhs) {
if (rhs.memory) {
this.resize_(rhs.size_);
this.memory[0..size_] = rhs.memory[0..rhs.size_];
Expand Down

0 comments on commit 3d33e04

Please sign in to comment.