summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/managed/ManagedContainer.hpp22
-rw-r--r--test/core/managed/ManagedContainerTest.cpp12
2 files changed, 25 insertions, 9 deletions
diff --git a/src/core/managed/ManagedContainer.hpp b/src/core/managed/ManagedContainer.hpp
index 067a789..bdab38f 100644
--- a/src/core/managed/ManagedContainer.hpp
+++ b/src/core/managed/ManagedContainer.hpp
@@ -222,7 +222,7 @@ public:
ManagedContainer(std::initializer_list<value_type> l) : owner(nullptr), c(l)
{
initialize();
- };
+ }
/**
* Constructor of the ManagedContainer class.
@@ -322,7 +322,7 @@ public:
ManagedContainer(own_type &&other)
: owner(other.owner), c(std::move(other.c))
{
- other.owner = nullptr;
+ //other.owner = nullptr;
}
/**
@@ -338,7 +338,7 @@ public:
{
initialize();
other.finalize(c);
- other.owner = nullptr;
+ //other.owner = nullptr;
}
/**
@@ -356,7 +356,7 @@ public:
{
initialize();
other.finalize(c);
- other.owner = nullptr;
+ //other.owner = nullptr;
}
/**
@@ -413,11 +413,23 @@ public:
finalize();
owner = other.owner;
c = std::move(other.c);
- other.owner = nullptr;
+ //other.owner = nullptr;
return *this;
}
/**
+ * Copy assignment while keeping the owner.
+ *
+ * @param other is the collection instance that should be copied.
+ */
+ void assign(const own_type &other)
+ {
+ finalize();
+ c = other.c;
+ initialize();
+ }
+
+ /**
* Equality operator.
*/
bool operator==(const own_type &other)
diff --git a/test/core/managed/ManagedContainerTest.cpp b/test/core/managed/ManagedContainerTest.cpp
index 643ba2b..1ae14cb 100644
--- a/test/core/managed/ManagedContainerTest.cpp
+++ b/test/core/managed/ManagedContainerTest.cpp
@@ -106,7 +106,8 @@ TEST(ManagedVector, moveAssignment)
}
v1 = std::move(v2);
- ASSERT_EQ(nullptr, v2.getOwner());
+ ASSERT_EQ(root, v2.getOwner());
+ ASSERT_TRUE(v2.empty());
}
for (bool v : a) {
ASSERT_TRUE(v);
@@ -172,7 +173,8 @@ TEST(ManagedVector, copyWithNewOwner)
ManagedVector<TestManaged> v3{root, v2};
v1 = std::move(v3);
- ASSERT_EQ(nullptr, v3.getOwner());
+ ASSERT_EQ(root, v3.getOwner());
+ ASSERT_TRUE(v3.empty());
ASSERT_TRUE(v1 != v2);
}
for (bool v : a) {
@@ -207,8 +209,10 @@ TEST(ManagedVector, moveWithNewOwner)
ManagedVector<TestManaged> v3{root, std::move(v2)};
v1 = std::move(v3);
- ASSERT_EQ(nullptr, v2.getOwner());
- ASSERT_EQ(nullptr, v3.getOwner());
+ ASSERT_EQ(root2, v2.getOwner());
+ ASSERT_TRUE(v2.empty());
+ ASSERT_EQ(root, v3.getOwner());
+ ASSERT_TRUE(v3.empty());
}
for (bool v : a) {
ASSERT_TRUE(v);