Commit 8fe3898d authored by Simon Heybrock's avatar Simon Heybrock
Browse files

Re #16476. Manual cow_ptr move implementation and unit tests.

parent 5a481fdc
......@@ -71,9 +71,14 @@ public:
/// Constructs a cow_ptr with no managed object, i.e. empty cow_ptr.
constexpr cow_ptr(std::nullptr_t) : Data(nullptr) {}
cow_ptr(const cow_ptr<DataType> &);
cow_ptr(cow_ptr<DataType> &&) = default;
// Move is hand-written, since std::mutex member prevents auto-generation.
cow_ptr(cow_ptr<DataType> &&other) : Data(std::move(other.Data)) {}
cow_ptr<DataType> &operator=(const cow_ptr<DataType> &);
cow_ptr<DataType> &operator=(cow_ptr<DataType> &&) = default;
// Move is hand-written, since std::mutex member prevents auto-generation.
cow_ptr<DataType> &operator=(cow_ptr<DataType> &&rhs) {
Data = std::move(rhs.Data);
return *this;
}
cow_ptr<DataType> &operator=(const ptr_type &);
/// Returns the stored pointer.
......
......@@ -63,6 +63,23 @@ public:
2)
}
void test_move_constructor() {
auto resource = boost::make_shared<int>(42);
cow_ptr<int> source{resource};
cow_ptr<int> clone(std::move(source));
TS_ASSERT(!source);
TS_ASSERT_EQUALS(clone.get(), resource.get());
}
void test_move_assignment() {
auto resource = boost::make_shared<int>(42);
cow_ptr<int> source{resource};
cow_ptr<int> clone;
clone = std::move(source);
TS_ASSERT(!source);
TS_ASSERT_EQUALS(clone.get(), resource.get());
}
void test_copy_assign_nullptr() {
cow_ptr<MyType> cow1{nullptr};
TS_ASSERT(!cow1);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment