cppannotations/annotations/yo/iostreams/moving.yo
Frank B. Brokken 75d04f6683 typos
2016-11-08 21:54:15 +01:00

27 lines
977 B
Text

Stream classes (e.g.,, all stream classes covered in this chapter)
are movable and can be swapped. This implies that factory functions can be
designed for stream classes. Here is an example:
verb(
ofstream out(string const &name)
{
ofstream ret(name); // construct ofstream
return ret; // return value optimization, but
} // OK as moving is supported
int main()
{
ofstream mine(out("out")); // return value optimizations, but
// OK as moving is supported
ofstream base("base");
ofstream other;
base.swap(other); // swapping streams is OK
other = std::move(base); // moving streams is OK
// other = base; // this would fail: copy assignment
// is not available for streams
}
)