Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions source/stdcpp/list.d
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ extern(C++, class) struct list(Type, Allocator)
///
alias difference_type = ptrdiff_t;

///
ref list opAssign();

///
@disable this() @safe pure nothrow @nogc scope;

Expand Down Expand Up @@ -334,7 +331,14 @@ extern(C++, class) struct list(Type, Allocator)
this.remove(item);
}
///
ref list opAssign(ref const list!Type other);
ref list opAssign(ref const list other)
{
import core.lifetime : emplace;

destroy!false(this);
emplace!(list)(&this, other);
return this;
}
///
void assign(size_type count, ref const value_type value);
///
Expand Down Expand Up @@ -574,5 +578,12 @@ version (CppRuntime_Clang)
bool empty() const nothrow {return __sz() == 0; }

void clear() nothrow;

void __copy_assign_alloc(const ref __list_imp __c)
{
if (__node_alloc() != __c.__node_alloc())
clear();
__node_alloc() = __c.__node_alloc();
}
}
}
14 changes: 13 additions & 1 deletion source/stdcpp/test/list.d
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,23 @@ unittest
p.resize(3);
assert(p.size == 3);

list!int cp_obj = p; //opAssign
list!int cp_obj = p; // copy ctor
assert(cp_obj.size == 3);
cp_obj.clear();
cp_obj.push_back(45);
cp_obj.push_back(56);
assert(cp_obj.front == 45);
assert(cp_obj.back == 56);
}

unittest
{
import stdcpp.allocator;
allocator!int alloc_instance = allocator!(int).init;
auto q = list!int(8, 9);
assert(q.get_allocator == alloc_instance);
assert(q.size == 8);
auto p = list!int(3);
q = p; // opAssign
assert(q.size == 3); // after opAssign
}