This allows FileWriter objects to be returned from functions. A valid copy or move constructor is needed even in the case of copy elision / return value optimization. In that case a copy or move constructor must be defined, even though it is not called.
I encountered the need for this while working on test code. The type parameterized test cases need a factory function to create test objects, so they must be returnable from such functions.
The choice of a move constructor over a copy constructor was largely because the wrapped ofstream object is move constructible, but not copy constructible.
This allows
FileWriter
objects to be returned from functions. A valid copy or move constructor is needed even in the case of copy elision / return value optimization. In that case a copy or move constructor must be defined, even though it is not called.I encountered the need for this while working on test code. The type parameterized test cases need a factory function to create test objects, so they must be returnable from such functions.
The choice of a move constructor over a copy constructor was largely because the wrapped
ofstream
object is move constructible, but not copy constructible.