summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/27_io/basic_stringstream/assign/1.cc
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/testsuite/27_io/basic_stringstream/assign/1.cc
parent38278d8a9c97abd336ad3d565ecf7b18ad3d23ed (diff)
downloadgcc-9b81754858b271df999993ac7c195acfb4558387.tar.gz
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/testsuite/27_io/basic_stringstream/assign/1.cc')
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_stringstream/assign/1.cc100
1 files changed, 100 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/assign/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/assign/1.cc
new file mode 100644
index 00000000000..0465461c7cb
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/assign/1.cc
@@ -0,0 +1,100 @@
+// { dg-options "-std=gnu++11" }
+
+// Copyright (C) 2014 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.5.2 Assign and swap [stringstream.assign]
+
+#include <sstream>
+#include <string>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ std::stringstream s1;
+ s1 << "absence of a signal";
+ std::string s;
+ s1 >> s;
+
+ std::stringstream s2;
+ s2 = std::move(s1);
+ s2 >> s;
+ VERIFY(s == "of");
+
+ std::stringstream s3;
+ s3.swap(s2);
+ s3 >> s;
+ VERIFY(s == "a");
+
+ swap(s1, s3);
+ s1 >> s;
+ VERIFY(s == "signal");
+
+ s2 << "should never be used as a signal";
+ s1 = std::move(s2);
+ getline(s1, s);
+ VERIFY(s == "should never be used as a signal");
+ s3 = std::move(s1);
+ VERIFY(s3.eof());
+}
+
+void test02()
+{
+ std::stringstream s0;
+ s0 << " 1234.5 ";
+ std::stringstream s;
+ s = std::move(s0);
+ char c{};
+ s >> c;
+ VERIFY( c == '1' );
+ int i{};
+ s >> i;
+ VERIFY( i == 234 );
+ double d{};
+ s >> d;
+ VERIFY( d == .5 );
+}
+
+void test03()
+{
+#ifdef _GLIBCXX_USE_WCHAR_T
+ std::wstringstream s0;
+ s0 << L" 1234.5 ";
+ std::wstringstream s;
+ s = std::move(s0);
+ s.swap(s0);
+ swap(s, s0);
+ wchar_t c{};
+ s >> c;
+ VERIFY( c == L'1' );
+ int i{};
+ s >> i;
+ VERIFY( i == 234 );
+ double d{};
+ s >> d;
+ VERIFY( d == .5 );
+#endif
+}
+
+int
+main()
+{
+ test01();
+ test02();
+ test03();
+}