diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2014-09-22 14:34:09 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2014-09-22 14:34:09 +0100 |
commit | 9b81754858b271df999993ac7c195acfb4558387 (patch) | |
tree | 56471caae5e872ad7a27f4e39b5f246f4a5245c8 /libstdc++-v3/include/std/fstream | |
parent | 38278d8a9c97abd336ad3d565ecf7b18ad3d23ed (diff) | |
download | gcc-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/std/fstream')
-rw-r--r-- | libstdc++-v3/include/std/fstream | 130 |
1 files changed, 129 insertions, 1 deletions
diff --git a/libstdc++-v3/include/std/fstream b/libstdc++-v3/include/std/fstream index 4d802f1..fcf5f94 100644 --- a/libstdc++-v3/include/std/fstream +++ b/libstdc++-v3/include/std/fstream @@ -125,7 +125,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __state_type _M_state_last; /// Pointer to the beginning of internal buffer. - char_type* _M_buf; + char_type* _M_buf; /** * Actual size of internal buffer. This number is equal to the size @@ -226,6 +226,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ basic_filebuf(); +#if __cplusplus >= 201103L + basic_filebuf(const basic_filebuf&) = delete; + basic_filebuf(basic_filebuf&&); +#endif + /** * @brief The destructor closes the file first. */ @@ -233,6 +238,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ~basic_filebuf() { this->close(); } +#if __cplusplus >= 201103L + basic_filebuf& operator=(const basic_filebuf&) = delete; + basic_filebuf& operator=(basic_filebuf&&); + void swap(basic_filebuf&); +#endif + // Members: /** * @brief Returns true if the external file is open. @@ -504,6 +515,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION this->init(&_M_filebuf); this->open(__s, __mode); } + + basic_ifstream(const basic_ifstream&) = delete; + + basic_ifstream(basic_ifstream&& __rhs) + : __istream_type(std::move(__rhs)), + _M_filebuf(std::move(__rhs._M_filebuf)) + { __istream_type::set_rdbuf(&_M_filebuf); } #endif /** @@ -515,6 +533,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ~basic_ifstream() { } +#if __cplusplus >= 201103L + // 27.8.3.2 Assign and swap: + + basic_ifstream& + operator=(const basic_ifstream&) = delete; + + basic_ifstream& + operator=(basic_ifstream&& __rhs) + { + __istream_type::operator=(std::move(__rhs)); + _M_filebuf = std::move(__rhs._M_filebuf); + return *this; + } + + void + swap(basic_ifstream& __rhs) + { + __istream_type::swap(__rhs); + _M_filebuf.swap(__rhs._M_filebuf); + } +#endif + // Members: /** * @brief Accessing the underlying buffer. @@ -679,6 +719,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION this->init(&_M_filebuf); this->open(__s, __mode); } + + basic_ofstream(const basic_ofstream&) = delete; + + basic_ofstream(basic_ofstream&& __rhs) + : __ostream_type(std::move(__rhs)), + _M_filebuf(std::move(__rhs._M_filebuf)) + { __ostream_type::set_rdbuf(&_M_filebuf); } #endif /** @@ -690,6 +737,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ~basic_ofstream() { } +#if __cplusplus >= 201103L + // 27.8.3.2 Assign and swap: + + basic_ofstream& + operator=(const basic_ofstream&) = delete; + + basic_ofstream& + operator=(basic_ofstream&& __rhs) + { + __ostream_type::operator=(std::move(__rhs)); + _M_filebuf = std::move(__rhs._M_filebuf); + return *this; + } + + void + swap(basic_ofstream& __rhs) + { + __ostream_type::swap(__rhs); + _M_filebuf.swap(__rhs._M_filebuf); + } +#endif + // Members: /** * @brief Accessing the underlying buffer. @@ -852,6 +921,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION this->init(&_M_filebuf); this->open(__s, __mode); } + + basic_fstream(const basic_fstream&) = delete; + + basic_fstream(basic_fstream&& __rhs) + : __iostream_type(std::move(__rhs)), + _M_filebuf(std::move(__rhs._M_filebuf)) + { __iostream_type::set_rdbuf(&_M_filebuf); } #endif /** @@ -863,6 +939,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ~basic_fstream() { } +#if __cplusplus >= 201103L + // 27.8.3.2 Assign and swap: + + basic_fstream& + operator=(const basic_fstream&) = delete; + + basic_fstream& + operator=(basic_fstream&& __rhs) + { + __iostream_type::operator=(std::move(__rhs)); + _M_filebuf = std::move(__rhs._M_filebuf); + return *this; + } + + void + swap(basic_fstream& __rhs) + { + __iostream_type::swap(__rhs); + _M_filebuf.swap(__rhs._M_filebuf); + } +#endif + // Members: /** * @brief Accessing the underlying buffer. @@ -947,6 +1045,36 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } }; +#if __cplusplus >= 201103L + /// Swap specialization for filebufs. + template <class _CharT, class _Traits> + inline void + swap(basic_filebuf<_CharT, _Traits>& __x, + basic_filebuf<_CharT, _Traits>& __y) + { __x.swap(__y); } + + /// Swap specialization for ifstreams. + template <class _CharT, class _Traits> + inline void + swap(basic_ifstream<_CharT, _Traits>& __x, + basic_ifstream<_CharT, _Traits>& __y) + { __x.swap(__y); } + + /// Swap specialization for ofstreams. + template <class _CharT, class _Traits> + inline void + swap(basic_ofstream<_CharT, _Traits>& __x, + basic_ofstream<_CharT, _Traits>& __y) + { __x.swap(__y); } + + /// Swap specialization for fstreams. + template <class _CharT, class _Traits> + inline void + swap(basic_fstream<_CharT, _Traits>& __x, + basic_fstream<_CharT, _Traits>& __y) + { __x.swap(__y); } +#endif + _GLIBCXX_END_NAMESPACE_VERSION } // namespace |