mizvekov wrote:

A move constructor and move assignment can be implemented in terms of swap 
roughly so I believe:

```
struct Foo {
  Foo(Foo&& Other) {
    operator=(std::move(Other));
  }
  
  Foo& operator=(Foo &&Other) {
    Foo T;
    swap(*this, T);
    swap(*this, Other);
    return *this;
  }
};
```

That also leaves the moved from object in an empty state.

The advantage is that a swap implementation is a simple memberwise swap, and 
the resource management is reused from the destructor.

In other contexts, outside of LLVM, this is also a simple way to implement 
these operations in an exception-safe manner.

https://github.com/llvm/llvm-project/pull/180484
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to