diff mbox

Overload std::getline for rvalue streams

Message ID 20140812152007.GS6927@redhat.com
State New
Headers show

Commit Message

Jonathan Wakely Aug. 12, 2014, 3:20 p.m. UTC
We're missing these overloads required by C++11.

Tested x86_64-linux, committed to trunk.

I think this should go on the branches too, any objections?

Comments

Jonathan Wakely Aug. 26, 2014, 3:03 p.m. UTC | #1
On 12/08/14 16:20 +0100, Jonathan Wakely wrote:
>We're missing these overloads required by C++11.
>
>Tested x86_64-linux, committed to trunk.
>
>I think this should go on the branches too, any objections?

Committed to the 4.9 branch.
diff mbox

Patch

commit c904682994e3c1d77abe16a4a7366e191b6ef6bc
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Aug 12 15:24:35 2014 +0100

    	* include/bits/basic_string.h (getline): Qualify call to prevent ADL
    	and add overloads for rvalue streams.
    	* testsuite/21_strings/basic_string/inserters_extractors/char/12.cc:
    	New.
    	* testsuite/21_strings/basic_string/inserters_extractors/wchar_t/12.cc:
    	New.

diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h
index cd60376..6a54d0c 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -2811,7 +2811,23 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
     inline basic_istream<_CharT, _Traits>&
     getline(basic_istream<_CharT, _Traits>& __is,
 	    basic_string<_CharT, _Traits, _Alloc>& __str)
-    { return getline(__is, __str, __is.widen('\n')); }
+    { return std::getline(__is, __str, __is.widen('\n')); }
+
+#if __cplusplus >= 201103L
+  /// Read a line from an rvalue stream into a string.
+  template<typename _CharT, typename _Traits, typename _Alloc>
+    basic_istream<_CharT, _Traits>&
+    getline(basic_istream<_CharT, _Traits>&& __is,
+	    basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim)
+    { return std::getline(__is, __str, __delim); }
+
+  /// Read a line from an rvalue stream into a string.
+  template<typename _CharT, typename _Traits, typename _Alloc>
+    inline basic_istream<_CharT, _Traits>&
+    getline(basic_istream<_CharT, _Traits>&& __is,
+	    basic_string<_CharT, _Traits, _Alloc>& __str)
+    { return std::getline(__is, __str); }
+#endif
 
   template<>
     basic_istream<char>&
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/12.cc b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/12.cc
new file mode 100644
index 0000000..a0dda5f
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/12.cc
@@ -0,0 +1,38 @@ 
+// { 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/>.
+
+#include <string>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  std::string s;
+  getline(std::istringstream("First line\nSecond line\n"), s);
+  VERIFY( s == "First line" );
+  getline(std::istringstream("Third line\nFourth line\n"), s, 'r');
+  VERIFY( s == "Thi" );
+}
+
+int
+main()
+{
+  test01();
+}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/12.cc b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/12.cc
new file mode 100644
index 0000000..db20c02
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/12.cc
@@ -0,0 +1,38 @@ 
+// { 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/>.
+
+#include <string>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  std::wstring s;
+  getline(std::wistringstream(L"First line\nSecond line\n"), s);
+  VERIFY( s == L"First line" );
+  getline(std::wistringstream(L"Third line\nFourth line\n"), s, L'r');
+  VERIFY( s == L"Thi" );
+}
+
+int
+main()
+{
+  test01();
+}