[patch] Implement move semantics for iostreams

Jonathan Wakely jwakely@redhat.com
Mon Sep 22 13:35:00 GMT 2014


This adds move and swap functions to the iostream classes.

Although this is a pretty large patch, it's a pure addition that only
affects C++11 mode, and should have no effect on existing code because
it won't be moving or swapping streams.

I wanted to use C++14's std::exchange so I added std::__exchange to
<bits/move.h> and made std::exchange forward to that.

I needed to add a new constructor to basic_ostream that doesn't call
init(0), for basic_iostream's move constructor to use.  (I wonder why
our non-standard default constructors for basic_istream and
basic_ostream call init(nullptr), rather than doing nothing.  Derived
classes that want init(nullptr) to be called can do that by passing
nullptr to the standard basic_istream and basic_ostream constructors
taking a pointer, which would allow the default constructors to be
re-purposed to intentionally leave the object uninitialized).

To ensure that the explicit instantiations in the library include the
new functions I had to move several files from src/c++98 to src/c++11,
which makes the patch huge, so the new tests are in a separate,
gzipped file to keep this post below the mailing list size limits.

Tested x86_64-linux, committed to trunk.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 92112 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20140922/1ff9080e/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tests.txt.gz
Type: application/gzip
Size: 2906 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20140922/1ff9080e/attachment.gz>


More information about the Gcc-patches mailing list