OSDN Git Service

2009-12-03 Paolo Carlini <paolo.carlini@oracle.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / bits / basic_string.h
index 5ef6f00..a574bf6 100644 (file)
@@ -419,13 +419,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       /**
        *  @brief  Default constructor creates an empty string.
        */
-      basic_string()
-#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
-      : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc())
-#else
-      : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc())
-#endif
-      { }
+      inline
+      basic_string();
 
       /**
        *  @brief  Construct an empty string using allocator @a a.
@@ -1551,8 +1546,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *  max_size(), length_error is thrown.  The value of the string doesn't
        *  change if an error is thrown.
       */
-      basic_string&
-      replace(iterator __i1, iterator __i2, initializer_list<_CharT> __l)
+      basic_string& replace(iterator __i1, iterator __i2,
+                           initializer_list<_CharT> __l)
       { return this->replace(__i1, __i2, __l.begin(), __l.end()); }
 #endif // __GXX_EXPERIMENTAL_CXX0X__
 
@@ -1593,7 +1588,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
         static _CharT*
         _S_construct_aux(_Integer __beg, _Integer __end,
                         const _Alloc& __a, __true_type)
-        { return _S_construct(static_cast<size_type>(__beg), __end, __a); }
+        { return _S_construct(static_cast<size_type>(__beg),
+                             static_cast<value_type>(__end), __a); }
 
       template<class _InIterator>
         static _CharT*
@@ -1603,35 +1599,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
          return _S_construct_aux(__beg, __end, __a, _Integral());
         }
 
-      static _CharT*
-      _S_construct(_CharT* __beg, _CharT* __end, const _Alloc& __a)
-      {
-       __glibcxx_requires_valid_range(__beg, __end);
-       return _S_construct(__beg, __end - __beg, __a);
-      }
-
-      static _CharT*
-      _S_construct(const _CharT* __beg, const _CharT* __end, const _Alloc& __a)
-      {
-       __glibcxx_requires_valid_range(__beg, __end);
-       return _S_construct(__beg, __end - __beg, __a);
-      }
-
-      static _CharT*
-      _S_construct(iterator __beg, iterator __end, const _Alloc& __a)
-      {
-       __glibcxx_requires_valid_range(__beg, __end);
-       return _S_construct(__beg.base(), __end - __beg, __a);
-      }
-
-      static _CharT*
-      _S_construct(const_iterator __beg, const_iterator __end,
-                  const _Alloc& __a)
-      {
-       __glibcxx_requires_valid_range(__beg, __end);
-       return _S_construct(__beg.base(), __end - __beg, __a);
-      }
-
       // For Input Iterators, used in istreambuf_iterators, etc.
       template<class _InIterator>
         static _CharT*
@@ -1648,9 +1615,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       static _CharT*
       _S_construct(size_type __req, _CharT __c, const _Alloc& __a);
 
-      static _CharT*
-      _S_construct(const _CharT* __s, size_type __n, const _Alloc& __a);
-
     public:
 
       /**
@@ -2216,6 +2180,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
              size_type __n2) const;
   };
 
+  template<typename _CharT, typename _Traits, typename _Alloc>
+    inline basic_string<_CharT, _Traits, _Alloc>::
+    basic_string()
+#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
+    : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { }
+#else
+    : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()) { }
+#endif
+
   // operator+
   /**
    *  @brief  Concatenate two strings.
@@ -2667,6 +2640,30 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
   { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); }
 
   // NB: (v)snprintf vs sprintf.
+
+  // DR 1261.
+  inline string
+  to_string(int __val)
+  { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 * sizeof(int),
+                                          "%d", __val); }
+
+  inline string
+  to_string(unsigned __val)
+  { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
+                                          4 * sizeof(unsigned),
+                                          "%u", __val); }
+
+  inline string
+  to_string(long __val)
+  { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 * sizeof(long),
+                                          "%ld", __val); }
+
+  inline string
+  to_string(unsigned long __val)
+  { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
+                                          4 * sizeof(unsigned long),
+                                          "%lu", __val); }
+
   inline string
   to_string(long long __val)
   { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
@@ -2680,6 +2677,24 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
                                           "%llu", __val); }
 
   inline string
+  to_string(float __val)
+  {
+    const int __n = 
+      __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20;
+    return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
+                                          "%f", __val);
+  }
+
+  inline string
+  to_string(double __val)
+  {
+    const int __n = 
+      __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20;
+    return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
+                                          "%f", __val);
+  }
+
+  inline string
   to_string(long double __val)
   {
     const int __n = 
@@ -2727,6 +2742,29 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
   stold(const wstring& __str, size_t* __idx = 0)
   { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); }
 
+  // DR 1261.
+  inline wstring
+  to_wstring(int __val)
+  { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 * sizeof(int),
+                                           L"%d", __val); }
+
+  inline wstring
+  to_wstring(unsigned __val)
+  { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
+                                           4 * sizeof(unsigned),
+                                           L"%u", __val); }
+
+  inline wstring
+  to_wstring(long __val)
+  { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 * sizeof(long),
+                                           L"%ld", __val); }
+
+  inline wstring
+  to_wstring(unsigned long __val)
+  { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
+                                           4 * sizeof(unsigned long),
+                                           L"%lu", __val); }
+
   inline wstring
   to_wstring(long long __val)
   { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
@@ -2740,6 +2778,24 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
                                            L"%llu", __val); }
 
   inline wstring
+  to_wstring(float __val)
+  {
+    const int __n =
+      __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20;
+    return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
+                                           L"%f", __val);
+  }
+
+  inline wstring
+  to_wstring(double __val)
+  {
+    const int __n =
+      __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20;
+    return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
+                                           L"%f", __val);
+  }
+
+  inline wstring
   to_wstring(long double __val)
   {
     const int __n =