basic_string.h (getline): Qualify call to prevent ADL and add overloads for rvalue streams.

* 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.

From-SVN: r213869
This commit is contained in:
Jonathan Wakely 2014-08-12 16:19:53 +01:00 committed by Jonathan Wakely
parent 909310bc4d
commit 191736612d
4 changed files with 102 additions and 1 deletions

View File

@ -1,3 +1,12 @@
2014-08-12 Jonathan Wakely <jwakely@redhat.com>
* 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.
2014-08-09 Ulrich Drepper <drepper@gmail.com>
* include/ext/random.tcc (uniform_on_sphere_helper): Define.

View File

@ -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>&

View File

@ -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();
}

View File

@ -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();
}