This is the mail archive of the libstdc++@sourceware.cygnus.com 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]

patch for std::string s(10,0)


Hi

Here is a patch for 21.3.1 para 15, the special handling for

  template<class InputIterator>
  basic_string(InputIterator begin, InputIterator end,
               const Allocater& a = Allocater())

when InputIterator is an integral type

Philip




1999-12-21  Philip Martin  <pm@corris.dircon.co.uk>

	* bits/basic_string.h: Add special case handling for integral
	"iterators".
	* bits/std_string.h: include type_traits.h



diff -c3prN libstdc++/bits/basic_string.h libstdc++-modified/bits/basic_string.h
*** libstdc++/bits/basic_string.h	Tue Nov 30 21:21:46 1999
--- libstdc++-modified/bits/basic_string.h	Tue Dec 21 21:46:45 1999
*************** namespace std {
*** 678,689 ****
          _M_replace(iterator __i1, iterator __i2, _FwdIterator __j1, 
  		   _FwdIterator __j2, forward_iterator_tag);
  
        template<class _InIter>
          static _CharT*
!         _S_construct(_InIter __beg, _InIter __end, const _Alloc& __a)
          { 
  	  typedef typename iterator_traits<_InIter>::iterator_category _Tag;
  	  return _S_construct(__beg, __end, __a, _Tag()); 
  	}
  
        // For Input Iterators, used in istreambuf_iterators, etc.
--- 678,709 ----
          _M_replace(iterator __i1, iterator __i2, _FwdIterator __j1, 
  		   _FwdIterator __j2, forward_iterator_tag);
  
+       // _S_construct_aux is used to implement the 21.3.1 para 15 which
+       // requires special behaviour if _InIter is an integral type
        template<class _InIter>
          static _CharT*
!         _S_construct_aux(_InIter __beg, _InIter __end, const _Alloc& __a,
!                          __false_type)
          { 
  	  typedef typename iterator_traits<_InIter>::iterator_category _Tag;
  	  return _S_construct(__beg, __end, __a, _Tag()); 
+ 	}
+ 
+       template<class _InIter>
+         static _CharT*
+         _S_construct_aux(_InIter __beg, _InIter __end, const _Alloc& __a,
+                          __true_type)
+         { 
+ 	  return _S_construct(static_cast<size_type>(__beg),
+                               static_cast<value_type>(__end), __a);
+ 	}
+ 
+       template<class _InIter>
+         static _CharT*
+         _S_construct(_InIter __beg, _InIter __end, const _Alloc& __a)
+         { 
+           typedef typename _Is_integer<_InIter>::_Integral _Integral;
+ 	  return _S_construct_aux(__beg, __end, __a, _Integral());
  	}
  
        // For Input Iterators, used in istreambuf_iterators, etc.
diff -c3prN libstdc++/bits/std_string.h libstdc++-modified/bits/std_string.h
*** libstdc++/bits/std_string.h	Mon Dec  6 21:52:53 1999
--- libstdc++-modified/bits/std_string.h	Tue Dec 21 21:47:27 1999
***************
*** 38,43 ****
--- 38,44 ----
  #include <bits/stl_string_fwd.h>
  #include <bits/std_iterator.h>
  #include <bits/char_traits.h>
+ #include <bits/type_traits.h>
  #include <bits/std_iosfwd.h> // for operators >>, <<, and getline decls
  #include <bits/basic_string.h>
  
diff -c3prN libstdc++/testsuite/21_strings/ctor_copy_dtor.cc libstdc++-modified/testsuite/21_strings/ctor_copy_dtor.cc
*** libstdc++/testsuite/21_strings/ctor_copy_dtor.cc	Tue Nov  9 19:07:12 1999
--- libstdc++-modified/testsuite/21_strings/ctor_copy_dtor.cc	Tue Dec 21 22:14:25 1999
*************** int test01(void)
*** 160,166 ****
    return test;
  }
  
! void test02() { std::string s(10,0); }
  
  int main()
  { 
--- 160,178 ----
    return test;
  }
  
! void test02()
! {
!   bool test = true;
! 
!   // template<typename _InputIter>
!   //   basic_string(_InputIter begin, _InputIter end, const allocator& a)
!   // where _InputIter is integral [21.3.1 para 15]
!   std::string s(10,0);
!   test &= s.size() == 10;
! #ifdef DEBUG_ASSERT
!   assert(test);
! #endif
! }
  
  int main()
  { 

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