aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Kosnik <bkoz@redhat.com>2001-04-30 20:53:31 +0000
committerBenjamin Kosnik <bkoz@gcc.gnu.org>2001-04-30 20:53:31 +0000
commitb85381b9118efe88eda38eeb83358dae6b315688 (patch)
tree111d6c64cb69489385bc3d36595f3b33b6a46850
parent60de6385e1b6b764dca5e467fa2c17e8822777f1 (diff)
downloadgcc-b85381b9118efe88eda38eeb83358dae6b315688.zip
gcc-b85381b9118efe88eda38eeb83358dae6b315688.tar.gz
gcc-b85381b9118efe88eda38eeb83358dae6b315688.tar.bz2
ostreambuf_iterator.cc: New file.
2001-04-30 Benjamin Kosnik <bkoz@redhat.com> libstdc++/2627 * testsuite/24_iterators/ostreambuf_iterator.cc: New file. * include/bits/sbuf_iter.h (ostreambuf_iterator): Remove bogus specializations. From-SVN: r41694
-rw-r--r--libstdc++-v3/ChangeLog7
-rw-r--r--libstdc++-v3/include/bits/sbuf_iter.h91
-rw-r--r--libstdc++-v3/testsuite/24_iterators/ostreambuf_iterator.cc97
3 files changed, 127 insertions, 68 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 1821a9f..acbaaff 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,12 @@
2001-04-30 Benjamin Kosnik <bkoz@redhat.com>
+ libstdc++/2627
+ * testsuite/24_iterators/ostreambuf_iterator.cc: New file.
+ * include/bits/sbuf_iter.h (ostreambuf_iterator): Remove bogus
+ specializations.
+
+2001-04-30 Benjamin Kosnik <bkoz@redhat.com>
+
libstdc++/2964
* include/bits/stl_iterator_base_funcs.h (__advance): Fix.
diff --git a/libstdc++-v3/include/bits/sbuf_iter.h b/libstdc++-v3/include/bits/sbuf_iter.h
index 052b0df..6bec6d2 100644
--- a/libstdc++-v3/include/bits/sbuf_iter.h
+++ b/libstdc++-v3/include/bits/sbuf_iter.h
@@ -36,29 +36,23 @@
namespace std
{
-
template<typename _CharT, typename _Traits>
class ostreambuf_iterator
-#if 1 // XXX this is standard:
: public iterator<output_iterator_tag, _CharT, void, void, void>
-#else
- : public output_iterator
-#endif
{
public:
-
// Types:
- typedef _CharT char_type;
+ typedef _CharT char_type;
typedef _Traits traits_type;
typedef basic_streambuf<_CharT, _Traits> streambuf_type;
typedef basic_ostream<_CharT, _Traits> ostream_type;
inline
ostreambuf_iterator(ostream_type& __s) throw ()
- : _M_sbuf(__s.rdbuf()), _M_failed(false) { }
+ : _M_sbuf(__s.rdbuf()), _M_failed(!_M_sbuf) { }
ostreambuf_iterator(streambuf_type* __s) throw ()
- : _M_sbuf(__s), _M_failed(false) { }
+ : _M_sbuf(__s), _M_failed(!_M_sbuf) { }
ostreambuf_iterator&
operator=(_CharT __c);
@@ -82,57 +76,19 @@ namespace std
private:
streambuf_type* _M_sbuf;
bool _M_failed;
-
-#if 0
- template<>
- friend char const*
- copy(char const* __first, char const* __last,
- ostreambuf_iterator<char,char_traits<char> > __to);
- template<>
- friend wchar_t const*
- copy(wchar_t const* __first, wchar_t const* __last,
- ostreambuf_iterator<wchar_t,char_traits<wchar_t> > __to);
-#endif
};
template<typename _CharT, typename _Traits>
inline ostreambuf_iterator<_CharT, _Traits>&
ostreambuf_iterator<_CharT, _Traits>::operator=(_CharT __c)
{
- if (!_M_failed &&
+ if (!_M_failed &&
_Traits::eq_int_type(_M_sbuf->sputc(__c),_Traits::eof()))
_M_failed = true;
return *this;
}
-#if 0
- // Optimized specializations of standard algorithms
- // These are specialized only for standard types
- // (with no unbound arguments) to avoid creating
- // overload problems with user specializations.
-
- template<>
- char const*
- copy(char const* __first, char const* __last,
- ostreambuf_iterator<char,char_traits<char> > __to)
- {
- if (!__to._M_failed)
- __to._M_sbuf->sputn(__first, __last-__first);
- return __last;
- }
-
- template<>
- wchar_t const*
- copy(wchar_t const* __first, wchar_t const* __last,
- ostreambuf_iterator<whar_t,char_traits<wchar_t> > __to)
- {
- if (!__to._M_failed)
- __to._M_sbuf->sputn(__first, __last-__first);
- return __last;
- }
-#endif
-
// 24.5.3 Template class istreambuf_iterator
template<class _CharT, class _Traits>
class istreambuf_iterator
@@ -151,13 +107,13 @@ namespace std
typedef istreambuf_iterator<_CharT, _Traits> __istreambufiter_type;
istreambuf_iterator() throw()
- : _M_istreambuf(NULL), _M_c(-2) { }
+ : _M_sbuf(NULL), _M_c(-2) { }
istreambuf_iterator(istream_type& __s) throw()
- : _M_istreambuf(__s.rdbuf()), _M_c(-2) { }
+ : _M_sbuf(__s.rdbuf()), _M_c(-2) { }
istreambuf_iterator(streambuf_type* __s) throw()
- : _M_istreambuf(__s), _M_c(-2) { }
+ : _M_sbuf(__s), _M_c(-2) { }
// NB: This should really have an int_type return
// value, so "end of stream" postion can be checked without
@@ -167,10 +123,10 @@ namespace std
{
// The result of operator*() on an end of stream is undefined.
char_type __ret;
- if (_M_istreambuf && _M_c != static_cast<int_type>(-2))
+ if (_M_sbuf && _M_c != static_cast<int_type>(-2))
__ret = _M_c;
- else if (_M_istreambuf)
- __ret = traits_type::to_char_type(_M_istreambuf->sgetc());
+ else if (_M_sbuf)
+ __ret = traits_type::to_char_type(_M_sbuf->sgetc());
else
__ret = static_cast<char_type>(traits_type::eof());
return __ret;
@@ -179,8 +135,8 @@ namespace std
__istreambufiter_type&
operator++()
{
- if (_M_istreambuf)
- _M_istreambuf->sbumpc();
+ if (_M_sbuf)
+ _M_sbuf->sbumpc();
_M_c = -2;
return *this;
}
@@ -192,8 +148,8 @@ namespace std
const __istreambufiter_type
operator++(int)
{
- if (_M_istreambuf)
- _M_c = _M_istreambuf->sbumpc();
+ if (_M_sbuf)
+ _M_c = _M_sbuf->sbumpc();
return *this;
}
#endif
@@ -202,9 +158,9 @@ namespace std
equal(const __istreambufiter_type& __b)
{
int_type __eof = traits_type::eof();
- bool __thiseof = !_M_istreambuf || _M_istreambuf->sgetc() == __eof;
- bool __beof = !__b._M_istreambuf
- || __b._M_istreambuf->sgetc() == __eof;
+ bool __thiseof = !_M_sbuf || _M_sbuf->sgetc() == __eof;
+ bool __beof = !__b._M_sbuf
+ || __b._M_sbuf->sgetc() == __eof;
return (__thiseof && __beof || (!__thiseof && !__beof));
}
@@ -215,9 +171,9 @@ namespace std
equal(const __istreambufiter_type& __b) const
{
int_type __eof = traits_type::eof();
- bool __thiseof = !_M_istreambuf || _M_istreambuf->sgetc() == __eof;
- bool __beof = !__b._M_istreambuf
- || __b._M_istreambuf->sgetc() == __eof;
+ bool __thiseof = !_M_sbuf || _M_sbuf->sgetc() == __eof;
+ bool __beof = !__b._M_sbuf
+ || __b._M_sbuf->sgetc() == __eof;
return (__thiseof && __beof || (!__thiseof && !__beof));
}
#endif
@@ -230,7 +186,7 @@ namespace std
// the "end of stream" iterator value.
// NB: This implementation assumes the "end of stream" value
// is EOF, or -1.
- streambuf_type* _M_istreambuf;
+ streambuf_type* _M_sbuf;
int_type _M_c;
};
@@ -246,7 +202,6 @@ namespace std
const istreambuf_iterator<_CharT, _Traits>& __b)
{ return !__a.equal(__b); }
-} // std::
-
-#endif /* _CPP_BITS_SBUF_ITER_H */
+} // namespace std
+#endif
diff --git a/libstdc++-v3/testsuite/24_iterators/ostreambuf_iterator.cc b/libstdc++-v3/testsuite/24_iterators/ostreambuf_iterator.cc
new file mode 100644
index 0000000..9f1544f
--- /dev/null
+++ b/libstdc++-v3/testsuite/24_iterators/ostreambuf_iterator.cc
@@ -0,0 +1,97 @@
+// 2001-04-30 Benjamin Kosnik <bkoz@redhat.com>
+
+// Copyright (C) 2001 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 2, 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 COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 24.5.4 template class ostreambuf_iterator
+
+#include <sstream>
+#include <iterator>
+#include <debug_assert.h>
+
+bool test01(void)
+{
+ typedef std::ostreambuf_iterator<char> costreambuf_iter;
+ typedef costreambuf_iter::streambuf_type cstreambuf_type;
+ bool test = true;
+ const char slit01[] = "playa hermosa, liberia, guanacaste";
+ std::string str01(slit01);
+ std::string tmp;
+ std::stringbuf strbuf01;
+ std::stringbuf strbuf02(str01);
+ std::ostringstream ostrs00(str01);
+ std::ostringstream ostrs01(str01);
+
+ // ctor sanity checks
+ costreambuf_iter ostrb_it01(ostrs00);
+ VERIFY( !ostrb_it01.failed() );
+ ostrb_it01++;
+ ++ostrb_it01;
+ VERIFY( !ostrb_it01.failed() );
+ ostrb_it01 = 'a';
+ VERIFY( !ostrb_it01.failed() );
+ *ostrb_it01;
+ VERIFY( !ostrb_it01.failed() );
+
+ costreambuf_iter ostrb_it02(NULL);
+ VERIFY( ostrb_it02.failed() );
+ ostrb_it02++;
+ ++ostrb_it02;
+ VERIFY( ostrb_it02.failed() );
+ *ostrb_it02;
+ VERIFY( ostrb_it02.failed() );
+ ostrb_it02 = 'a';
+ VERIFY( ostrb_it02.failed() );
+
+ // charT operator*() const
+ // ostreambuf_iterator& operator++();
+ // ostreambuf_iterator& operator++(int);
+ costreambuf_iter ostrb_it27(ostrs00);
+ VERIFY( !ostrb_it27.failed() );
+ for (int i = 0; i < strlen(slit01) - 2; ++i)
+ ostrb_it27 = 'a';
+ VERIFY( !ostrb_it27.failed() );
+ tmp = ostrs00.str();
+ VERIFY ( tmp == str01 );
+
+ costreambuf_iter ostrb_it28(ostrs01);
+ VERIFY( !ostrb_it28.failed() );
+ for (int i = 0; i < strlen(slit01) + 1; ++i)
+ ostrb_it28 = 'b';
+ VERIFY( !ostrb_it28.failed() );
+ tmp = ostrs01.str();
+ VERIFY ( tmp != str01 );
+
+#ifdef DEBUG_ASSERT
+ assert(test);
+#endif
+
+ return test;
+}
+
+int main()
+{
+ test01();
+
+ return 0;
+}
+
+
+
+
+