mirror of
https://gitlab.com/fbb-git/cppannotations
synced 2024-11-16 07:48:44 +01:00
27 lines
977 B
Text
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
|
|
}
|
|
)
|
|
|