aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include
diff options
context:
space:
mode:
authorFrançois Dumont <fdumont@gcc.gnu.org>2017-11-20 22:30:28 +0000
committerFrançois Dumont <fdumont@gcc.gnu.org>2017-11-20 22:30:28 +0000
commite324f9cb921234b80c809f8ffbd7ef2d55d583bc (patch)
treed38add252c2ed6e4905d28d1855e6e3306405a91 /libstdc++-v3/include
parent9be0a9d6d20e5cb3c50f64b5a9a49070b9a0f267 (diff)
downloadgcc-e324f9cb921234b80c809f8ffbd7ef2d55d583bc.zip
gcc-e324f9cb921234b80c809f8ffbd7ef2d55d583bc.tar.gz
gcc-e324f9cb921234b80c809f8ffbd7ef2d55d583bc.tar.bz2
streambuf_iterator.h (istreambuf_iterator<>): Declare std::advance for istreambuf_iterator of char types to be friend.
2017-11-20 François Dumont <fdumont@gcc.gnu.org> * include/bits/streambuf_iterator.h (istreambuf_iterator<>): Declare std::advance for istreambuf_iterator of char types to be friend. (std::advance(istreambuf_iterator&, _Distance)): New overload. * include/std/streambuf (basic_streambuf<>): Declare std::advance for istreambuf_iterator of char types to be friend. * testsuite/22_locale/money_get/get/char/9.cc: Have istreambuf_iterator created on the fly when calling money_get<>::get. * testsuite/22_locale/money_get/get/wchar_t/9.cc: Likewise. * testsuite/24_iterators/istreambuf_iterator/debug/1_neg.cc: New. * testsuite/24_iterators/istreambuf_iterator/debug/2_neg.cc: New. * testsuite/25_algorithms/advance/istreambuf_iterators/char/1.cc: New. * testsuite/25_algorithms/advance/istreambuf_iterators/char/1_neg.cc: New. * testsuite/25_algorithms/advance/istreambuf_iterators/char/2.cc: New. * testsuite/25_algorithms/advance/istreambuf_iterators/char/2_neg.cc: New. * testsuite/25_algorithms/advance/istreambuf_iterators/char/3_neg.cc: New. * testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/1.cc: New. * testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/1_neg.cc: New. * testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2.cc: New. * testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2_neg.cc: New. * testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/3_neg.cc: New. * testsuite/25_algorithms/find/istreambuf_iterators/char/2.cc: Leverage on std::advance overload. * testsuite/25_algorithms/find/istreambuf_iterators/wchar_t/2.cc: Likewise. From-SVN: r254972
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r--libstdc++-v3/include/bits/streambuf_iterator.h84
-rw-r--r--libstdc++-v3/include/std/streambuf5
2 files changed, 71 insertions, 18 deletions
diff --git a/libstdc++-v3/include/bits/streambuf_iterator.h b/libstdc++-v3/include/bits/streambuf_iterator.h
index 081afe5..98f29b4 100644
--- a/libstdc++-v3/include/bits/streambuf_iterator.h
+++ b/libstdc++-v3/include/bits/streambuf_iterator.h
@@ -38,7 +38,7 @@
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
-
+
/**
* @addtogroup iterators
* @{
@@ -49,7 +49,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _CharT, typename _Traits>
class istreambuf_iterator
: public iterator<input_iterator_tag, _CharT, typename _Traits::off_type,
- _CharT*,
+ _CharT*,
#if __cplusplus >= 201103L
// LWG 445.
_CharT>
@@ -70,22 +70,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _CharT2>
friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
- ostreambuf_iterator<_CharT2> >::__type
+ ostreambuf_iterator<_CharT2> >::__type
copy(istreambuf_iterator<_CharT2>, istreambuf_iterator<_CharT2>,
ostreambuf_iterator<_CharT2>);
template<bool _IsMove, typename _CharT2>
- friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
+ friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
_CharT2*>::__type
__copy_move_a2(istreambuf_iterator<_CharT2>,
istreambuf_iterator<_CharT2>, _CharT2*);
template<typename _CharT2>
friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
- istreambuf_iterator<_CharT2> >::__type
+ istreambuf_iterator<_CharT2> >::__type
find(istreambuf_iterator<_CharT2>, istreambuf_iterator<_CharT2>,
const _CharT2&);
+ template<typename _CharT2, typename _Distance>
+ friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
+ void>::__type
+ advance(istreambuf_iterator<_CharT2>&, _Distance);
+
private:
// 24.5.3 istreambuf_iterator
// p 1
@@ -214,15 +219,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Types:
//@{
/// Public typedefs
- typedef _CharT char_type;
- typedef _Traits traits_type;
+ typedef _CharT char_type;
+ typedef _Traits traits_type;
typedef basic_streambuf<_CharT, _Traits> streambuf_type;
typedef basic_ostream<_CharT, _Traits> ostream_type;
//@}
template<typename _CharT2>
friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
- ostreambuf_iterator<_CharT2> >::__type
+ ostreambuf_iterator<_CharT2> >::__type
copy(istreambuf_iterator<_CharT2>, istreambuf_iterator<_CharT2>,
ostreambuf_iterator<_CharT2>);
@@ -283,7 +288,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Overloads for streambuf iterators.
template<typename _CharT>
typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
- ostreambuf_iterator<_CharT> >::__type
+ ostreambuf_iterator<_CharT> >::__type
copy(istreambuf_iterator<_CharT> __first,
istreambuf_iterator<_CharT> __last,
ostreambuf_iterator<_CharT> __result)
@@ -299,8 +304,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
template<bool _IsMove, typename _CharT>
- typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
- ostreambuf_iterator<_CharT> >::__type
+ typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
+ ostreambuf_iterator<_CharT> >::__type
__copy_move_a2(_CharT* __first, _CharT* __last,
ostreambuf_iterator<_CharT> __result)
{
@@ -323,15 +328,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
template<bool _IsMove, typename _CharT>
- typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
- _CharT*>::__type
+ typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
+ _CharT*>::__type
__copy_move_a2(istreambuf_iterator<_CharT> __first,
istreambuf_iterator<_CharT> __last, _CharT* __result)
{
- typedef istreambuf_iterator<_CharT> __is_iterator_type;
- typedef typename __is_iterator_type::traits_type traits_type;
+ typedef istreambuf_iterator<_CharT> __is_iterator_type;
+ typedef typename __is_iterator_type::traits_type traits_type;
typedef typename __is_iterator_type::streambuf_type streambuf_type;
- typedef typename traits_type::int_type int_type;
+ typedef typename traits_type::int_type int_type;
if (__first._M_sbuf && !__last._M_sbuf)
{
@@ -363,10 +368,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
find(istreambuf_iterator<_CharT> __first,
istreambuf_iterator<_CharT> __last, const _CharT& __val)
{
- typedef istreambuf_iterator<_CharT> __is_iterator_type;
+ typedef istreambuf_iterator<_CharT> __is_iterator_type;
typedef typename __is_iterator_type::traits_type traits_type;
typedef typename __is_iterator_type::streambuf_type streambuf_type;
- typedef typename traits_type::int_type int_type;
+ typedef typename traits_type::int_type int_type;
const int_type __eof = traits_type::eof();
if (__first._M_sbuf && !__last._M_sbuf)
@@ -397,6 +402,49 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __first;
}
+ template<typename _CharT, typename _Distance>
+ typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
+ void>::__type
+ advance(istreambuf_iterator<_CharT>& __i, _Distance __n)
+ {
+ if (__n == 0)
+ return;
+
+ __glibcxx_assert(__n > 0);
+ __glibcxx_requires_cond(!__i._M_at_eof(),
+ _M_message(__gnu_debug::__msg_inc_istreambuf)
+ ._M_iterator(__i));
+
+ typedef istreambuf_iterator<_CharT> __is_iterator_type;
+ typedef typename __is_iterator_type::traits_type traits_type;
+ typedef typename __is_iterator_type::streambuf_type streambuf_type;
+ typedef typename traits_type::int_type int_type;
+ const int_type __eof = traits_type::eof();
+
+ streambuf_type* __sb = __i._M_sbuf;
+ while (__n > 0)
+ {
+ streamsize __size = __sb->egptr() - __sb->gptr();
+ if (__size > __n)
+ {
+ __sb->__safe_gbump(__n);
+ break;
+ }
+
+ __sb->__safe_gbump(__size);
+ __n -= __size;
+ if (traits_type::eq_int_type(__sb->underflow(), __eof))
+ {
+ __glibcxx_requires_cond(__n == 0,
+ _M_message(__gnu_debug::__msg_inc_istreambuf)
+ ._M_iterator(__i));
+ break;
+ }
+ }
+
+ __i._M_c = __eof;
+ }
+
// @} group iterators
_GLIBCXX_END_NAMESPACE_VERSION
diff --git a/libstdc++-v3/include/std/streambuf b/libstdc++-v3/include/std/streambuf
index a05b46e..c1fd395 100644
--- a/libstdc++-v3/include/std/streambuf
+++ b/libstdc++-v3/include/std/streambuf
@@ -159,6 +159,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
find(istreambuf_iterator<_CharT2>, istreambuf_iterator<_CharT2>,
const _CharT2&);
+ template<typename _CharT2, typename _Distance>
+ friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
+ void>::__type
+ advance(istreambuf_iterator<_CharT2>&, _Distance);
+
template<typename _CharT2, typename _Traits2>
friend basic_istream<_CharT2, _Traits2>&
operator>>(basic_istream<_CharT2, _Traits2>&, _CharT2*);