streambuf_iterator.h (istreambuf_iterator<>): Declare std::advance for istreambuf_ite...
authorFrançois Dumont <fdumont@gcc.gnu.org>
Mon, 20 Nov 2017 22:30:28 +0000 (22:30 +0000)
committerFrançois Dumont <fdumont@gcc.gnu.org>
Mon, 20 Nov 2017 22:30:28 +0000 (22:30 +0000)
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

19 files changed:
libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/streambuf_iterator.h
libstdc++-v3/include/std/streambuf
libstdc++-v3/testsuite/22_locale/money_get/get/char/9.cc
libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/9.cc
libstdc++-v3/testsuite/24_iterators/istreambuf_iterator/debug/1_neg.cc [new file with mode: 0644]
libstdc++-v3/testsuite/24_iterators/istreambuf_iterator/debug/2_neg.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/1.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/1_neg.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2_neg.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/3_neg.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/1.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/1_neg.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2_neg.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/3_neg.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/char/2.cc
libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/wchar_t/2.cc

index 367d40f1a2d8b31b439f92183cec4a243a399224..40f0076002c6a2f0370f34794632f25f0c55fb5a 100644 (file)
@@ -1,3 +1,38 @@
+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.
+
 2017-11-20  Jonathan Wakely  <jwakely@redhat.com>
 
        * testsuite/special_functions/18_riemann_zeta/check_value.cc: Fix
index 081afe59d840ffb893128579d76c787ada97e7d8..98f29b488d145acdb693083601f39de51cb7cca9 100644 (file)
@@ -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
index a05b46e8199c4993d9602d321722dfefd21923af..c1fd395b827026a12c38d5a740acc437510724ad 100644 (file)
@@ -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*);
index 9b69956d82c79dd2ae080c8ca91b40ee39e4125b..476e38fadc2870011717b4c1d6b3cfe6134af5ab 100644 (file)
@@ -41,7 +41,6 @@ int main()
     = std::use_facet<std::money_get<char> >(liffey.getloc());
 
   typedef std::istreambuf_iterator<char> iterator_type;
-  iterator_type is(liffey);
   iterator_type end;
 
   std::ios_base::iostate err01 = std::ios_base::goodbit;
@@ -50,7 +49,7 @@ int main()
 
   // Feed it 1 digit too many, which should fail.
   liffey.str("12.3456");
-  greed.get(is, end, false, liffey, err01, coins);
+  greed.get(liffey, end, false, liffey, err01, coins);
   if (! (err01 & std::ios_base::failbit ))
     fails |= 0x01;
 
@@ -58,7 +57,7 @@ int main()
 
   // Feed it exactly what it wants, which should succeed.
   liffey.str("12.345");
-  greed.get(is, end, false, liffey, err01, coins);
+  greed.get(liffey, end, false, liffey, err01, coins);
   if ( err01 & std::ios_base::failbit )
     fails |= 0x02;
 
@@ -66,7 +65,7 @@ int main()
 
   // Feed it 1 digit too few, which should fail.
   liffey.str("12.34");
-  greed.get(is, end, false, liffey, err01, coins);
+  greed.get(liffey, end, false, liffey, err01, coins);
   if (! ( err01 & std::ios_base::failbit ))
     fails |= 0x04;
 
@@ -74,7 +73,7 @@ int main()
 
   // Feed it only a decimal-point, which should fail.
   liffey.str("12.");
-  greed.get(is, end, false, liffey, err01, coins);
+  greed.get(liffey, end, false, liffey, err01, coins);
   if (! (err01 & std::ios_base::failbit ))
     fails |= 0x08;
 
@@ -82,7 +81,7 @@ int main()
 
   // Feed it no decimal-point at all, which should succeed.
   liffey.str("12");
-  greed.get(is, end, false, liffey, err01, coins);
+  greed.get(liffey, end, false, liffey, err01, coins);
   if ( err01 & std::ios_base::failbit )
     fails |= 0x10;
 
index a08a713540a729437f5e17069092bf9405cdd337..e5f8defdb0a19d834e3f9cf4576b400bdb6fb967 100644 (file)
@@ -41,7 +41,6 @@ int main()
     = std::use_facet<std::money_get<wchar_t> >(liffey.getloc());
 
   typedef std::istreambuf_iterator<wchar_t> iterator_type;
-  iterator_type is(liffey);
   iterator_type end;
 
   std::ios_base::iostate err01 = std::ios_base::goodbit;
@@ -50,7 +49,7 @@ int main()
 
   // Feed it 1 digit too many, which should fail.
   liffey.str(L"12.3456");
-  greed.get(is, end, false, liffey, err01, coins);
+  greed.get(liffey, end, false, liffey, err01, coins);
   if (! (err01 & std::ios_base::failbit ))
     fails |= 0x01;
 
@@ -58,7 +57,7 @@ int main()
 
   // Feed it exactly what it wants, which should succeed.
   liffey.str(L"12.345");
-  greed.get(is, end, false, liffey, err01, coins);
+  greed.get(liffey, end, false, liffey, err01, coins);
   if ( err01 & std::ios_base::failbit )
     fails |= 0x02;
 
@@ -66,7 +65,7 @@ int main()
 
   // Feed it 1 digit too few, which should fail.
   liffey.str(L"12.34");
-  greed.get(is, end, false, liffey, err01, coins);
+  greed.get(liffey, end, false, liffey, err01, coins);
   if (! ( err01 & std::ios_base::failbit ))
     fails |= 0x04;
 
@@ -74,7 +73,7 @@ int main()
 
   // Feed it only a decimal-point, which should fail.
   liffey.str(L"12.");
-  greed.get(is, end, false, liffey, err01, coins);
+  greed.get(liffey, end, false, liffey, err01, coins);
   if (! (err01 & std::ios_base::failbit ))
     fails |= 0x08;
 
@@ -82,7 +81,7 @@ int main()
 
   // Feed it no decimal-point at all, which should succeed.
   liffey.str(L"12");
-  greed.get(is, end, false, liffey, err01, coins);
+  greed.get(liffey, end, false, liffey, err01, coins);
   if ( err01 & std::ios_base::failbit )
     fails |= 0x10;
 
diff --git a/libstdc++-v3/testsuite/24_iterators/istreambuf_iterator/debug/1_neg.cc b/libstdc++-v3/testsuite/24_iterators/istreambuf_iterator/debug/1_neg.cc
new file mode 100644 (file)
index 0000000..241fc58
--- /dev/null
@@ -0,0 +1,35 @@
+// Copyright (C) 2017 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/>.
+
+// { dg-do run { xfail *-*-* } }
+// { dg-require-debug-mode "" }
+
+#include <iterator>
+
+void test01()
+{
+  typedef std::istreambuf_iterator<char> cistreambuf_iter;
+
+  cistreambuf_iter eof;
+  ++eof; // Invalid.
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/24_iterators/istreambuf_iterator/debug/2_neg.cc b/libstdc++-v3/testsuite/24_iterators/istreambuf_iterator/debug/2_neg.cc
new file mode 100644 (file)
index 0000000..407f00b
--- /dev/null
@@ -0,0 +1,35 @@
+// Copyright (C) 2017 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/>.
+
+// { dg-do run { xfail *-*-* } }
+// { dg-require-debug-mode "" }
+
+#include <iterator>
+
+void test01()
+{
+  typedef std::istreambuf_iterator<char> cistreambuf_iter;
+
+  cistreambuf_iter eof;
+  eof++; // Invalid.
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/1.cc b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/1.cc
new file mode 100644 (file)
index 0000000..7c3f882
--- /dev/null
@@ -0,0 +1,56 @@
+// Copyright (C) 2017 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 <iterator>
+#include <sstream>
+#include <algorithm>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  using namespace std;
+
+  typedef istreambuf_iterator<char> in_iterator_type;
+
+  const char data1[] = "Drei Phantasien nach Friedrich Holderlin";
+  const string str1(data1);
+  istringstream iss1(str1);
+  in_iterator_type beg1(iss1);
+  in_iterator_type end1;
+
+  VERIFY( *beg1 == 'D' );
+
+  advance(beg1, 1);
+
+  VERIFY( beg1 != end1 );
+  VERIFY( *beg1 == 'r' );
+
+  advance(beg1, 0);
+  VERIFY( *beg1 == 'r' );
+
+  advance(beg1, 38);
+  VERIFY( *beg1 == 'n' );
+
+  advance(beg1, 1);
+  VERIFY( beg1 == end1 );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/1_neg.cc b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/1_neg.cc
new file mode 100644 (file)
index 0000000..d1b8cde
--- /dev/null
@@ -0,0 +1,38 @@
+// Copyright (C) 2017 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/>.
+
+// { dg-do run { xfail *-*-* } }
+// { dg-require-debug-mode "" }
+
+#include <iterator>
+#include <algorithm>
+
+void test01()
+{
+  using namespace std;
+
+  typedef istreambuf_iterator<char> in_iterator_type;
+  in_iterator_type end1;
+
+  advance(end1, -1); // Invalid -1 value.
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2.cc b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2.cc
new file mode 100644 (file)
index 0000000..c99111e
--- /dev/null
@@ -0,0 +1,82 @@
+// Copyright (C) 2017 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/>.
+
+// { dg-require-fileio "" }
+
+#include <iterator>
+#include <fstream>
+#include <algorithm>
+
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  using namespace std;
+
+  typedef istreambuf_iterator<char> in_iterator_type;
+
+  unsigned found = 0;
+
+  {
+    ifstream fbuf("istream_unformatted-1.txt");
+
+    in_iterator_type beg(fbuf);
+    in_iterator_type end;
+
+    for (;;)
+      {
+       beg = find(beg, end, '1');
+       if (beg == end)
+         break;
+
+       ++found;
+       VERIFY( *beg == '1' );
+
+       advance(beg, 9);
+       VERIFY( *beg == '0' );
+      }
+  }
+
+  {
+    ifstream fbuf("istream_unformatted-1.txt");
+
+    in_iterator_type beg(fbuf);
+    in_iterator_type end;
+
+    beg = find(beg, end, '1');
+    VERIFY( beg != end );
+    VERIFY( *beg == '1' );
+
+    advance(beg, 9);
+    VERIFY( *beg == '0' );
+
+    unsigned line_length = 10;
+    while (*++beg != '1')
+      ++line_length;
+
+    // Try to jump directly to the end through advance.
+    advance(beg, (found - 2) * line_length + 9);
+    VERIFY( *beg == '0' );
+    VERIFY( find(beg, end, '1') == end );
+  }
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2_neg.cc b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2_neg.cc
new file mode 100644 (file)
index 0000000..9d18778
--- /dev/null
@@ -0,0 +1,40 @@
+// Copyright (C) 2017 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/>.
+
+// { dg-do run { xfail *-*-* } }
+// { dg-require-debug-mode "" }
+
+#include <iterator>
+#include <algorithm>
+
+void test01()
+{
+  using namespace std;
+
+  typedef istreambuf_iterator<char> in_iterator_type;
+  in_iterator_type end1;
+
+  advance(end1, 0); // Ok.
+
+  advance(end1, 1); // Invalid.
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/3_neg.cc b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/3_neg.cc
new file mode 100644 (file)
index 0000000..af2bed6
--- /dev/null
@@ -0,0 +1,43 @@
+// Copyright (C) 2017 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/>.
+
+// { dg-do run { xfail *-*-* } }
+// { dg-require-debug-mode "" }
+
+#include <sstream>
+#include <iterator>
+#include <algorithm>
+
+void test01()
+{
+  using namespace std;
+
+  typedef istreambuf_iterator<char> in_iterator_type;
+
+  const char data1[] = "Drei Phantasien nach Friedrich Holderlin";
+  const string str1(data1);
+  istringstream iss1(str1);
+  in_iterator_type beg1(iss1);
+
+  advance(beg1, 50); // Invalid
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/1.cc b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/1.cc
new file mode 100644 (file)
index 0000000..18839ca
--- /dev/null
@@ -0,0 +1,56 @@
+// Copyright (C) 2017 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 <iterator>
+#include <sstream>
+#include <algorithm>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  using namespace std;
+
+  typedef istreambuf_iterator<wchar_t> in_iterator_type;
+
+  const wchar_t data1[] = L"Drei Phantasien nach Friedrich Holderlin";
+  const wstring str1(data1);
+  wistringstream iss1(str1);
+  in_iterator_type beg1(iss1);
+  in_iterator_type end1;
+
+  VERIFY( *beg1 == L'D' );
+
+  advance(beg1, 1);
+
+  VERIFY( beg1 != end1 );
+  VERIFY( *beg1 == L'r' );
+
+  advance(beg1, 0);
+  VERIFY( *beg1 == L'r' );
+
+  advance(beg1, 38);
+  VERIFY( *beg1 == L'n' );
+
+  advance(beg1, 1);
+  VERIFY( beg1 == end1 );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/1_neg.cc b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/1_neg.cc
new file mode 100644 (file)
index 0000000..cd1b7a1
--- /dev/null
@@ -0,0 +1,38 @@
+// Copyright (C) 2017 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/>.
+
+// { dg-do run { xfail *-*-* } }
+// { dg-require-debug-mode "" }
+
+#include <iterator>
+#include <algorithm>
+
+void test01()
+{
+  using namespace std;
+
+  typedef istreambuf_iterator<wchar_t> in_iterator_type;
+  in_iterator_type end1;
+
+  advance(end1, -1); // Invalid -1 value.
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2.cc b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2.cc
new file mode 100644 (file)
index 0000000..91cc939
--- /dev/null
@@ -0,0 +1,82 @@
+// Copyright (C) 2017 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/>.
+
+// { dg-require-fileio "" }
+
+#include <iterator>
+#include <fstream>
+#include <algorithm>
+
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  using namespace std;
+
+  typedef istreambuf_iterator<wchar_t> in_iterator_type;
+
+  unsigned found = 0;
+
+  {
+    wifstream fbuf("istream_unformatted-1.txt");
+
+    in_iterator_type beg(fbuf);
+    in_iterator_type end;
+
+    for (;;)
+      {
+       beg = find(beg, end, L'1');
+       if (beg == end)
+         break;
+
+       ++found;
+       VERIFY( *beg == L'1' );
+
+       advance(beg, 9);
+       VERIFY( *beg == L'0' );
+      }
+  }
+
+  {
+    wifstream fbuf("istream_unformatted-1.txt");
+
+    in_iterator_type beg(fbuf);
+    in_iterator_type end;
+
+    beg = find(beg, end, L'1');
+    VERIFY( beg != end );
+    VERIFY( *beg == L'1' );
+
+    advance(beg, 9);
+    VERIFY( *beg == L'0' );
+
+    unsigned line_length = 10;
+    while (*++beg != L'1')
+      ++line_length;
+
+    // Try to jump directly to the end through advance.
+    advance(beg, (found - 2) * line_length + 9);
+    VERIFY( *beg == L'0' );
+    VERIFY( find(beg, end, L'1') == end );
+  }
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2_neg.cc b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2_neg.cc
new file mode 100644 (file)
index 0000000..ea280f9
--- /dev/null
@@ -0,0 +1,40 @@
+// Copyright (C) 2017 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/>.
+
+// { dg-do run { xfail *-*-* } }
+// { dg-require-debug-mode "" }
+
+#include <iterator>
+#include <algorithm>
+
+void test01()
+{
+  using namespace std;
+
+  typedef istreambuf_iterator<wchar_t> in_iterator_type;
+  in_iterator_type end1;
+
+  advance(end1, 0); // Ok.
+
+  advance(end1, 1); // Invalid.
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/3_neg.cc b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/3_neg.cc
new file mode 100644 (file)
index 0000000..c5bf122
--- /dev/null
@@ -0,0 +1,43 @@
+// Copyright (C) 2017 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/>.
+
+// { dg-do run { xfail *-*-* } }
+// { dg-require-debug-mode "" }
+
+#include <sstream>
+#include <iterator>
+#include <algorithm>
+
+void test01()
+{
+  using namespace std;
+
+  typedef istreambuf_iterator<wchar_t> in_iterator_type;
+
+  const wchar_t data1[] = L"Drei Phantasien nach Friedrich Holderlin";
+  const wstring str1(data1);
+  wistringstream iss1(str1);
+  in_iterator_type beg1(iss1);
+
+  advance(beg1, 50); // Invalid
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
index 125d59768c3bf4bbfc5fcdb054a1e15fb7b012ce..b288787132b93bc37bf003bc626e4865829b69ea 100644 (file)
@@ -46,8 +46,7 @@ void test01()
       ++found;
       VERIFY( *beg == '1' );
 
-      for (unsigned sk = 0; sk < 9; sk++)
-       ++beg;
+      advance(beg, 9);
       VERIFY( *beg == '0' );
     }
   VERIFY( found == 1500 );
index e8d2b887e44f8177e2bba6a7c1a6d096802ba60c..6393f49088e5be87dfe6d1fb1c92aca38ea1a75e 100644 (file)
@@ -44,8 +44,7 @@ void test01()
       ++found;
       VERIFY( *beg == L'1' );
 
-      for (unsigned sk = 0; sk < 9; sk++)
-       ++beg;
+      advance(beg, 9);
       VERIFY( *beg == L'0' );
     }
   VERIFY( found == 1500 );