In the paper P0135R0 there is an example:
struct NonMoveable {
NonMoveable(int);
NonMoveable(NonMoveable&) = delete;
void NonMoveable(NonMoveable&) = delete;
std::array<int, 1024> arr;
};
NonMoveable make() {
return NonMoveable(42); // ok, directly constructs returned object
}
auto nm = make(); // ok, directly constructs 'nm'
This confused me:
void NonMoveable(NonMoveable&) = delete;
What is it? How constructor can be void?
UPD. Someone linked probable answer - No! This question is totally different.
In C++20, the only copy allowed in the example is the one at line 3 (actually, x is implicitly moved from). Copy elision (NRVO) is allowed there and is routinely performed by most compilers, but is still non-guaranteed, and the widget class cannot be non-copyable non-movable.
Guaranteed copy elision redefines a number of C++ concepts, such that certain circumstances where copies/moves could be elided don't actually provoke a copy/move at all. The compiler isn't eliding a copy; the standard says that no such copying could ever happen. Consider this function: T Func() {return T();}
That "void" is what we would call a "typo". The intent was likely to remove the move assignment operator (though not strictly necessary, since deleting the copy constructor would do that). Considering that the person wrote "void", it's not surprising that the person also missed the &&
part, and forgot the const
in the copy constructor's parameter (also not strictly necessary).
Basically, there's a lot wrong there; someone wrote it in a hurry.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With