OSDN Git Service

2002-04-15 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / bits / basic_string.tcc
index 896cd02..3f4b5fb 100644 (file)
@@ -41,6 +41,8 @@
 #ifndef _CPP_BITS_STRING_TCC
 #define _CPP_BITS_STRING_TCC 1
 
+#pragma GCC system_header
+
 namespace std
 {
   template<typename _CharT, typename _Traits, typename _Alloc>
@@ -137,6 +139,10 @@ namespace std
       {
        size_type __dnew = static_cast<size_type>(distance(__beg, __end));
 
+       // NB: Not required, but considered best practice.
+       if (__builtin_expect(__beg == _InIter(0), 0))
+         __throw_logic_error("attempt to create string with null pointer");
+       
        if (__beg == __end && __a == _Alloc())
          return _S_empty_rep()._M_refcopy();
 
@@ -217,7 +223,8 @@ namespace std
   template<typename _CharT, typename _Traits, typename _Alloc>
     basic_string<_CharT, _Traits, _Alloc>::
     basic_string(const _CharT* __s, const _Alloc& __a)
-    : _M_dataplus(_S_construct(__s, __s + traits_type::length(__s), __a), __a)
+    : _M_dataplus(_S_construct(__s, __s ? __s + traits_type::length(__s) : 0, 
+                              __a), __a)
     { }
 
   template<typename _CharT, typename _Traits, typename _Alloc>
@@ -436,7 +443,7 @@ namespace std
       void* __place = _Raw_bytes_alloc(__alloc).allocate(__size);
       _Rep *__p = new (__place) _Rep;
       __p->_M_capacity = __capacity;
-      __p->_M_set_sharable();  // one reference
+      __p->_M_set_sharable();  // One reference.
       __p->_M_length = 0;
       return __p;
     }
@@ -490,14 +497,10 @@ namespace std
        this->erase(__n);
       // else nothing (in particular, avoid calling _M_mutate() unnecessarily.)
     }
-  
-  // This is the general replace helper, which gets instantiated both
-  // for input-iterators and forward-iterators. It buffers internally and
-  // then calls _M_replace_safe. For input-iterators this is almost the
-  // best we can do, but for forward-iterators many optimizations could be
-  // conceived: f.i., when source and destination ranges do not overlap
-  // buffering is not really needed. In order to easily implement them, it
-  // could become useful to add an _M_replace(forward_iterator_tag)
+
+  // This is the general replace helper, which currently gets instantiated both
+  // for input iterators and reverse iterators. It buffers internally and then
+  // calls _M_replace_safe.
   template<typename _CharT, typename _Traits, typename _Alloc>
     template<typename _InputIter>
       basic_string<_CharT, _Traits, _Alloc>&
@@ -511,10 +514,8 @@ namespace std
       }
 
   // This is a special replace helper, which does not buffer internally
-  // and can be used in the "safe" situations involving forward-iterators,
+  // and can be used in "safe" situations involving forward iterators,
   // i.e., when source and destination ranges are known to not overlap.
-  // Presently, is called by _M_replace, by the various append and by
-  // the assigns.
   template<typename _CharT, typename _Traits, typename _Alloc>
     template<typename _ForwardIter>
       basic_string<_CharT, _Traits, _Alloc>&
@@ -938,6 +939,37 @@ namespace std
       _Traits::copy(__buf, __str.data(), __bytes);
       __buf[__bytes] = _CharT();
     }
+
+  // Inhibit implicit instantiations for required instantiations,
+  // which are defined via explicit instantiations elsewhere.  
+  // NB: This syntax is a GNU extension.
+  extern template class basic_string<char>;
+  extern template 
+    basic_istream<char>& 
+    operator>>(basic_istream<char>&, string&);
+  extern template 
+    basic_ostream<char>& 
+    operator<<(basic_ostream<char>&, const string&);
+  extern template 
+    basic_istream<char>& 
+    getline(basic_istream<char>&, string&, char);
+  extern template 
+    basic_istream<char>& 
+    getline(basic_istream<char>&, string&);
+
+  extern template class basic_string<wchar_t>;
+  extern template 
+    basic_istream<wchar_t>& 
+    operator>>(basic_istream<wchar_t>&, wstring&);
+  extern template 
+    basic_ostream<wchar_t>& 
+    operator<<(basic_ostream<wchar_t>&, const wstring&);
+  extern template 
+    basic_istream<wchar_t>& 
+    getline(basic_istream<wchar_t>&, wstring&, wchar_t);
+  extern template 
+    basic_istream<wchar_t>& 
+    getline(basic_istream<wchar_t>&, wstring&);
 } // namespace std
 
 #endif