Record References: fix copy and assignment handling
not entirely sure about the design, but lets try this approach: they can be "cloned" and likewise move-assigned, but we do not allow the regular assignment, because this would enable to use references like pointers (what we deliberately do not want)
This commit is contained in:
parent
7650b36f1e
commit
0bff4f21d5
2 changed files with 16 additions and 2 deletions
|
|
@ -514,7 +514,20 @@ namespace diff{
|
|||
/** prevent moving into black hole */
|
||||
RecordRef(Target&&) = delete;
|
||||
|
||||
// standard copy operations acceptable
|
||||
RecordRef(RecordRef const&) = default;
|
||||
RecordRef(RecordRef &&) = default;
|
||||
|
||||
/** references can not be reassigned */
|
||||
RecordRef& operator= (RecordRef const&) = delete;
|
||||
RecordRef& operator= (RecordRef &) = delete;
|
||||
|
||||
/** assignment is not allowed, but moving is */
|
||||
RecordRef&
|
||||
operator= (RecordRef &&o)
|
||||
{
|
||||
std::swap(record_, o.record_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
explicit
|
||||
|
|
|
|||
|
|
@ -326,12 +326,13 @@ namespace test{
|
|||
CHECK ("🌰" == oor.getType());
|
||||
CHECK (oor.get("♄") == "saturn");
|
||||
|
||||
// are copyable and assignable
|
||||
// are copyable but not reassignable
|
||||
RecordRef<string> r2 = ref;
|
||||
CHECK (r2);
|
||||
CHECK (r2.get() == ref.get());
|
||||
CHECK (!isSameObject (r2, ref));
|
||||
|
||||
// but references are move-assignable
|
||||
empty = std::move(r2);
|
||||
CHECK (empty);
|
||||
CHECK (!r2);
|
||||
|
|
|
|||
Loading…
Reference in a new issue