The example does not compile with VS 2019 if you do not specify the generic parameter explicitly.
Also move constructor and move assignment operators should be noexcept I think.
Also, the consumer function parameter should be void consumer(SimpleUniquePointer&& consumer_ptr)
and not void consumer(SimpleUniquePointer consumerPtr);
The text was updated successfully, but these errors were encountered:
You are correct, C++17 should be enabled. (I've thought I was already compiling with this option).
noexcept is discussed in chapter 4 actually, where exceptions and constructors are discussed. Move constructor and move assignment in the example are made noexcept in the chapter example.
I think that defining foo f(bar x) is implicit overload. If you want to forbid rvalues as arguments, you have to explicitly delete foo f(bar&& x) which implies that function with this signature is generated by the compiler. In this case, the function accepting rvalue is the only one that is valid, and explicit is usually better than implicit, especially when teaching.
Hmm, it does matter a bit. Haven't tried with other compilers than visual studio, but when attempting to call a function with deleted copy constructor, you are going to get a sort of confusing error message complaining about lack of copy constructor, which points at deleted function. You won't be told about the function itself. In a larger scenario, for example if such a function is defined in a library with header and object file provided only, it is going to be hard to fix or diagnose, I think.