aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/ext/stdio_sync_filebuf.h
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2014-09-22 14:34:09 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2014-09-22 14:34:09 +0100
commit9b81754858b271df999993ac7c195acfb4558387 (patch)
tree56471caae5e872ad7a27f4e39b5f246f4a5245c8 /libstdc++-v3/include/ext/stdio_sync_filebuf.h
parent38278d8a9c97abd336ad3d565ecf7b18ad3d23ed (diff)
downloadgcc-9b81754858b271df999993ac7c195acfb4558387.zip
gcc-9b81754858b271df999993ac7c195acfb4558387.tar.gz
gcc-9b81754858b271df999993ac7c195acfb4558387.tar.bz2
Make streams movable and swappable.
PR libstdc++/54316 PR libstdc++/53626 * config/abi/pre/gnu.ver: Add new exports. * config/io/basic_file_stdio.h (__basic_file): Support moving and swapping. * include/bits/basic_ios.h (basic_ios::move, basic_ios::swap): Likewise. * include/bits/ios_base.h (ios_base::_M_move, ios_base::_M_swap): Likewise. * include/bits/fstream.tcc (basic_filebuf): Likewise. * include/bits/move.h (__exchange): Define for C++11 mode. * include/ext/stdio_filebuf.h (stdio_filebuf): Support moving and swapping. * include/ext/stdio_sync_filebuf.h (stdio_sync_filebuf): Likewise. * include/std/fstream (basic_filebuf, basic_ifstream, basic_ofstream, basic_fstream): Likewise. * include/std/ios: Remove whitespace. * include/std/istream (basic_istream, basic_iostream): Support moving and swapping. * include/std/ostream (basic_ostream): Likewise. * include/std/sstream (basic_stringbuf, basic_istringstream, basic_ostringstream, basic_stringstream): Likewise. * include/std/streambuf (basic_streambuf): Do not default copy constructor and assignment on first declaration. * include/std/utility (exchange): Forward to __exchange. * testsuite/27_io/basic_filebuf/cons/char/copy_neg.cc: New. * src/c++11/Makefile.am: Add stream-related files. * src/c++11/Makefile.in: Regenerate. * src/c++11/ext11-inst.cc (stdio_filebuf, stdio_sync_filebuf): New file for explicit instantiation definitions. * src/c++11/ios.cc: Move from src/c++98 to here. (ios_base::_M_move, ios_base::_M_swap): Define. * src/c++11/ios-inst.cc: Move from src/c++98 to here. * src/c++11/iostream-inst.cc: Likewise. * src/c++11/istream-inst.cc: Likewise. * src/c++11/ostream-inst.cc: Likewise. * src/c++11/sstream-inst.cc: Likewise. * src/c++11/streambuf-inst.cc: Likewise. * src/c++98/Makefile.am: Remove stream-related files. * src/c++98/Makefile.in: Regenerate. * src/c++98/ext-inst.cc (stdio_filebuf): Remove explicit instantiations. * src/c++98/misc-inst.cc (stdio_sync_filebuf): Likewise. * src/c++98/ios-inst.cc: Move to src/c++11/. * src/c++98/ios.cc: Move to src/c++11/. * src/c++98/iostream-inst.cc: Likewise. * src/c++98/istream-inst.cc: Likewise. * src/c++98/ostream-inst.cc: Likewise. * src/c++98/sstream-inst.cc: Likewise. * src/c++98/streambuf-inst.cc: Likewise. * testsuite/27_io/basic_filebuf/cons/char/copy_neg.cc: New. * testsuite/27_io/basic_fstream/cons/move.cc: New. * testsuite/27_io/basic_fstream/assign/1.cc: New. * testsuite/27_io/basic_ifstream/cons/move.cc: New. * testsuite/27_io/basic_ifstream/assign/1.cc: New. * testsuite/27_io/basic_istringstream/assign/1.cc: New. * testsuite/27_io/basic_istringstream/cons/move.cc: New. * testsuite/27_io/basic_ofstream/cons/move.cc: New. * testsuite/27_io/basic_ofstream/assign/1.cc: New. * testsuite/27_io/basic_ostringstream/assign/1.cc: New. * testsuite/27_io/basic_ostringstream/cons/move.cc: New. * testsuite/27_io/basic_stringstream/assign/1.cc: New. * testsuite/27_io/basic_stringstream/cons/move.cc: New. From-SVN: r215463
Diffstat (limited to 'libstdc++-v3/include/ext/stdio_sync_filebuf.h')
-rw-r--r--libstdc++-v3/include/ext/stdio_sync_filebuf.h32
1 files changed, 31 insertions, 1 deletions
diff --git a/libstdc++-v3/include/ext/stdio_sync_filebuf.h b/libstdc++-v3/include/ext/stdio_sync_filebuf.h
index 73283a7..c881172 100644
--- a/libstdc++-v3/include/ext/stdio_sync_filebuf.h
+++ b/libstdc++-v3/include/ext/stdio_sync_filebuf.h
@@ -35,6 +35,7 @@
#include <unistd.h>
#include <cstdio>
#include <bits/c++io.h> // For __c_file
+#include <bits/move.h> // For __exchange
#ifdef _GLIBCXX_USE_WCHAR_T
#include <cwchar>
@@ -64,8 +65,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
typedef typename traits_type::off_type off_type;
private:
+ typedef std::basic_streambuf<_CharT, _Traits> __streambuf_type;
+
// Underlying stdio FILE
- std::__c_file* const _M_file;
+ std::__c_file* _M_file;
// Last character gotten. This is used when pbackfail is
// called from basic_streambuf::sungetc()
@@ -77,6 +80,33 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
: _M_file(__f), _M_unget_buf(traits_type::eof())
{ }
+#if __cplusplus >= 201103L
+ stdio_sync_filebuf(stdio_sync_filebuf&& __fb) noexcept
+ : __streambuf_type(std::move(__fb)),
+ _M_file(__fb._M_file), _M_unget_buf(__fb._M_unget_buf)
+ {
+ __fb._M_file = nullptr;
+ __fb._M_unget_buf = traits_type::eof();
+ }
+
+ stdio_sync_filebuf&
+ operator=(stdio_sync_filebuf&& __fb) noexcept
+ {
+ __streambuf_type::operator=(__fb);
+ _M_file = std::__exchange(__fb._M_file, nullptr);
+ _M_unget_buf = std::__exchange(__fb._M_unget_buf, traits_type::eof());
+ return *this;
+ }
+
+ void
+ swap(stdio_sync_filebuf& __fb)
+ {
+ __streambuf_type::swap(__fb);
+ std::swap(_M_file, __fb._M_file);
+ std::swap(_M_unget_buf, __fb._M_unget_buf);
+ }
+#endif
+
/**
* @return The underlying FILE*.
*