This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: std::advance istreambuf_iterator overload


On 10/11/2017 21:57, Jonathan Wakely wrote:
On 09/11/17 22:12 +0100, François Dumont wrote:
Hi

    Working on istreambuf_iterator I realized that this iterator would really benefit from an std::advance overload so here it is.


    Tested under Linux x86_64 normal and debug modes, ok to commit ?

François


diff --git a/libstdc++-v3/include/bits/streambuf_iterator.h b/libstdc++-v3/include/bits/streambuf_iterator.h
index 0a6c7f9..b60626a 100644
--- a/libstdc++-v3/include/bits/streambuf_iterator.h
+++ b/libstdc++-v3/include/bits/streambuf_iterator.h
@@ -417,6 +421,55 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
      return __last;
    }

+  template<typename _CharT, typename _Distance>
+    inline _GLIBCXX17_CONSTEXPR void

This function can never be constexpr.

I just replicate the _GLIBCXX17_CONSTEXPR qualification of the general std::advance overload. I am not clear about those different constexpr concepts but I also found strange that it could be consider as such.


+ 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;

This function relies on private members of istreambuf_iterator which
may not be present in a user-defined specialization of
istreambuf_iterator.

I think realistically you can only do this optimization for
istreambuf_iterator<char> and istreambuf_iterator<wchar_t>. Look at
how the std::copy and std::find overloads are contrained with
__is_char.

I wondered why copy or find were constrained this way, thanks for explaining. I have done the same for std::advance.


+      int_type __c = __sb->sgetc();
+      while (__n && !traits_type::eq_int_type(__c, __eof))

Can we use __n > 0 as the condition? Would it give better behaviour
for negative values in non-debug mode?
Indeed, it is better with this check.

+    {
+      streamsize __size = __sb->egptr() - __sb->gptr();
+      if (__size > __n)
+        {
+          __sb->__safe_gbump(__n);
+          __n = 0;
+        }
+      else if (__size > 1)
+        {
+          __sb->__safe_gbump(__size);
+          __n -= __size;
+          __c = __sb->underflow();
+        }
+      else
+        {
+          --__n;
+          __c = __sb->snextc();
+        }

It seems like it should be possible to optimize this loop, but I don't
see an obvious way to improve it.
It sounds like a Fermat quotes :-)

But I thought twice about this implementation and here is a new proposal.

François

diff --git a/libstdc++-v3/include/bits/streambuf_iterator.h b/libstdc++-v3/include/bits/streambuf_iterator.h
index 0a6c7f9..177f6f7 100644
--- a/libstdc++-v3/include/bits/streambuf_iterator.h
+++ b/libstdc++-v3/include/bits/streambuf_iterator.h
@@ -86,6 +86,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);
+
     private:
       // 24.5.3 istreambuf_iterator
       // p 1
@@ -417,6 +422,50 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       return __last;
     }
 
+  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);
+	      __n = 0;
+	      break;
+	    }
+
+	  __sb->__safe_gbump(__size);
+	  __n -= __size;
+	  if (traits_type::eq_int_type(__sb->underflow(), __eof))
+	    break;
+	}
+
+      __glibcxx_requires_cond(__n == 0,
+			      _M_message(__gnu_debug::__msg_inc_istreambuf)
+			      ._M_iterator(__i));
+      __i._M_c = __eof;
+      if (traits_type::eq_int_type(__sb->sgetc(), __eof))
+	__i._M_sbuf = 0;
+    }
+
 // @} 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*);
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
index 0000000..7c3f882
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/1.cc
@@ -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
index 0000000..d1b8cde
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/1_neg.cc
@@ -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
index 0000000..c99111e
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2.cc
@@ -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
index 0000000..9d18778
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2_neg.cc
@@ -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
index 0000000..af2bed6
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/3_neg.cc
@@ -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
index 0000000..18839ca
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/1.cc
@@ -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
index 0000000..cd1b7a1
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/1_neg.cc
@@ -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
index 0000000..91cc939
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2.cc
@@ -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
index 0000000..ea280f9
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2_neg.cc
@@ -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
index 0000000..c5bf122
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/3_neg.cc
@@ -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;
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/char/2.cc b/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/char/2.cc
index 125d597..b288787 100644
--- a/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/char/2.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/char/2.cc
@@ -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 );
diff --git a/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/wchar_t/2.cc b/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/wchar_t/2.cc
index e8d2b88..6393f49 100644
--- a/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/wchar_t/2.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/wchar_t/2.cc
@@ -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 );

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]