diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index efb05eadf49..e1d798e0e1f 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,16 @@ +2008-06-29 Paolo Carlini + + * src/string_conversions.cc: Remove. + * config/abi/pre/gnu.ver: Delete exports. + * src/Makefile.am: Update. + * include/ext/string_conversions.h: Add. + * include/Makefile.am: Update. + * include/bits/basic_string.h: Include string_conversions.h, + define numeric conversion functions. + * include/ext/vstring.h: Likewise. + * src/Makefile.in: Regenerate. + * include/Makefile.in: Regenerate. + 2008-06-29 Paolo Carlini * include/bits/stl_algo.h (copy_n): Add in C++0x mode. diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver index 9bec6f56cb3..4578ce513fc 100644 --- a/libstdc++-v3/config/abi/pre/gnu.ver +++ b/libstdc++-v3/config/abi/pre/gnu.ver @@ -896,11 +896,6 @@ GLIBCXX_3.4.11 { # char16_t and char32_t _ZNSt14numeric_limitsIu8char*; - # string conversions - _ZSt?sto*; - _ZSt9to_string*; - _ZSt10to_wstring*; - } GLIBCXX_3.4.10; # Symbols in the support library (libsupc++) have their own tag. diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index 8ef1fce0426..a8f48c7d282 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -499,6 +499,7 @@ ext_headers = \ ${ext_srcdir}/rope \ ${ext_srcdir}/ropeimpl.h \ ${ext_srcdir}/slist \ + ${ext_srcdir}/string_conversions.h \ ${ext_srcdir}/throw_allocator.h \ ${ext_srcdir}/typelist.h \ ${ext_srcdir}/type_traits.h \ diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in index f96020f9f26..8c1e626934f 100644 --- a/libstdc++-v3/include/Makefile.in +++ b/libstdc++-v3/include/Makefile.in @@ -750,6 +750,7 @@ ext_headers = \ ${ext_srcdir}/rope \ ${ext_srcdir}/ropeimpl.h \ ${ext_srcdir}/slist \ + ${ext_srcdir}/string_conversions.h \ ${ext_srcdir}/throw_allocator.h \ ${ext_srcdir}/typelist.h \ ${ext_srcdir}/type_traits.h \ diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 99ef4bb7b40..19c79d11cf7 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -2473,42 +2473,138 @@ _GLIBCXX_BEGIN_NAMESPACE(std) wchar_t __delim); #endif +_GLIBCXX_END_NAMESPACE #if (defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_C99)) +#include + +_GLIBCXX_BEGIN_NAMESPACE(std) + // 21.4 Numeric Conversions [string.conversions]. - int stoi(const string&, size_t* = 0, int = 10); - long stol(const string&, size_t* = 0, int = 10); - unsigned long stoul(const string&, size_t* = 0, int = 10); - long long stoll(const string&, size_t* = 0, int = 10); - unsigned long long stoull(const string&, size_t* = 0, int = 10); + inline int + stoi(const string& __str, size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa(&std::strtol, "stoi", __str.c_str(), + __idx, __base); } - float stof(const string&, size_t* = 0); - double stod(const string&, size_t* = 0); - long double stold(const string&, size_t* = 0); + inline long + stol(const string& __str, size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(), + __idx, __base); } - string to_string(long long); - string to_string(unsigned long long); - string to_string(long double); + inline unsigned long + stoul(const string& __str, size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(), + __idx, __base); } + + inline long long + stoll(const string& __str, size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(), + __idx, __base); } + + inline unsigned long long + stoull(const string& __str, size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(), + __idx, __base); } + + // NB: strtof vs strtod. + inline float + stof(const string& __str, size_t* __idx = 0) + { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); } + + inline double + stod(const string& __str, size_t* __idx = 0) + { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); } + + inline long double + stold(const string& __str, size_t* __idx = 0) + { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); } + + // NB: (v)snprintf vs sprintf. + inline string + to_string(long long __val) + { return __gnu_cxx::__to_xstring(&std::vsnprintf, + 4 * sizeof(long long), + "%lld", __val); } + + inline string + to_string(unsigned long long __val) + { return __gnu_cxx::__to_xstring(&std::vsnprintf, + 4 * sizeof(unsigned long long), + "%llu", __val); } + + inline string + to_string(long double __val) + { + const int __n = + __gnu_cxx::__numeric_traits::__max_exponent10 + 20; + return __gnu_cxx::__to_xstring(&std::vsnprintf, __n, + "%Lf", __val); + } #ifdef _GLIBCXX_USE_WCHAR_T - int stoi(const wstring&, size_t* = 0, int = 10); - long stol(const wstring&, size_t* = 0, int = 10); - unsigned long stoul(const wstring&, size_t* = 0, int = 10); - long long stoll(const wstring&, size_t* = 0, int = 10); - unsigned long long stoull(const wstring&, size_t* = 0, int = 10); + inline int + stoi(const wstring& __str, size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa(&std::wcstol, "stoi", __str.c_str(), + __idx, __base); } - float stof(const wstring&, size_t* = 0); - double stod(const wstring&, size_t* = 0); - long double stold(const wstring&, size_t* = 0); + inline long + stol(const wstring& __str, size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(), + __idx, __base); } - wstring to_wstring(long long); - wstring to_wstring(unsigned long long); - wstring to_wstring(long double); -#endif + inline unsigned long + stoul(const wstring& __str, size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(), + __idx, __base); } + inline long long + stoll(const wstring& __str, size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(), + __idx, __base); } + + inline unsigned long long + stoull(const wstring& __str, size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(), + __idx, __base); } + + // NB: wcstof vs wcstod. + inline float + stof(const wstring& __str, size_t* __idx = 0) + { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); } + + inline double + stod(const wstring& __str, size_t* __idx = 0) + { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); } + + inline long double + stold(const wstring& __str, size_t* __idx = 0) + { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); } + + inline wstring + to_wstring(long long __val) + { return __gnu_cxx::__to_xstring(&std::vswprintf, + 4 * sizeof(long long), + L"%lld", __val); } + + inline wstring + to_wstring(unsigned long long __val) + { return __gnu_cxx::__to_xstring(&std::vswprintf, + 4 * sizeof(unsigned long long), + L"%llu", __val); } + + inline wstring + to_wstring(long double __val) + { + const int __n = + __gnu_cxx::__numeric_traits::__max_exponent10 + 20; + return __gnu_cxx::__to_xstring(&std::vswprintf, __n, + L"%Lf", __val); + } #endif _GLIBCXX_END_NAMESPACE +#endif + #endif /* _BASIC_STRING_H */ diff --git a/libstdc++-v3/include/ext/string_conversions.h b/libstdc++-v3/include/ext/string_conversions.h new file mode 100644 index 00000000000..69bcce491f4 --- /dev/null +++ b/libstdc++-v3/include/ext/string_conversions.h @@ -0,0 +1,99 @@ +// String Conversions -*- C++ -*- + +// Copyright (C) 2008 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#ifndef _STRING_CONVERSIONS_H +#define _STRING_CONVERSIONS_H 1 + +#pragma GCC system_header + +#include +#include +#include +#include +#include +#include +#include + +_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) + + // Helper for all the sto* functions. + template + _Ret + __stoa(_TRet (*__convf) (const _CharT*, _CharT**, _Base...), + const char* __name, const _CharT* __str, std::size_t* __idx, + _Base... __base) + { + _Ret __ret; + + _CharT* __endptr; + errno = 0; + const _TRet __tmp = __convf(__str, &__endptr, __base...); + + if (__endptr == __str) + std::__throw_invalid_argument(__name); + else if (errno == ERANGE + || (std::__are_same<_Ret, int>::__value + && (__tmp < __numeric_traits::__min + || __tmp > __numeric_traits::__max))) + std::__throw_out_of_range(__name); + else + __ret = __tmp; + + if (__idx) + *__idx = __endptr - __str; + + return __ret; + } + + // Helper for the to_string / to_wstring functions. + template + _String + __to_xstring(int (*__convf) (_CharT*, std::size_t, const _CharT*, + __builtin_va_list), std::size_t __n, + const _CharT* __fmt, ...) + { + // XXX Eventually the result will be constructed in place in + // the C++0x string, likely with the help of internal hooks. + _CharT* __s = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) + * __n)); + + __builtin_va_list __args; + __builtin_va_start(__args, __fmt); + + const int __len = __convf(__s, __n, __fmt, __args); + + __builtin_va_end(__args); + + return _String(__s, __s + __len); + } + +_GLIBCXX_END_NAMESPACE + +#endif // _STRING_CONVERSIONS_H diff --git a/libstdc++-v3/include/ext/vstring.h b/libstdc++-v3/include/ext/vstring.h index a369cae2f0d..0e74bfa8cb2 100644 --- a/libstdc++-v3/include/ext/vstring.h +++ b/libstdc++-v3/include/ext/vstring.h @@ -1,6 +1,6 @@ // Versatile string -*- C++ -*- -// Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. +// Copyright (C) 2005, 2006, 2007, 2008 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 @@ -2321,6 +2321,136 @@ _GLIBCXX_BEGIN_NAMESPACE(std) _GLIBCXX_END_NAMESPACE +#if (defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_C99)) + +#include + +_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) + + // 21.4 Numeric Conversions [string.conversions]. + inline int + stoi(const __vstring& __str, std::size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa(&std::strtol, "stoi", __str.c_str(), + __idx, __base); } + + inline long + stol(const __vstring& __str, std::size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(), + __idx, __base); } + + inline unsigned long + stoul(const __vstring& __str, std::size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(), + __idx, __base); } + + inline long long + stoll(const __vstring& __str, std::size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(), + __idx, __base); } + + inline unsigned long long + stoull(const __vstring& __str, std::size_t* __idx, int __base = 10) + { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(), + __idx, __base); } + + // NB: strtof vs strtod. + inline float + stof(const __vstring& __str, std::size_t* __idx = 0) + { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); } + + inline double + stod(const __vstring& __str, std::size_t* __idx = 0) + { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); } + + inline long double + stold(const __vstring& __str, std::size_t* __idx = 0) + { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); } + + // NB: (v)snprintf vs sprintf. + inline __vstring + to_string(long long __val) + { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, + 4 * sizeof(long long), + "%lld", __val); } + + inline __vstring + to_string(unsigned long long __val) + { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, + 4 * sizeof(unsigned long long), + "%llu", __val); } + + inline __vstring + to_string(long double __val) + { + const int __n = __numeric_traits::__max_exponent10 + 20; + return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n, + "%Lf", __val); + } + +#ifdef _GLIBCXX_USE_WCHAR_T + inline int + stoi(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa(&std::wcstol, "stoi", __str.c_str(), + __idx, __base); } + + inline long + stol(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(), + __idx, __base); } + + inline unsigned long + stoul(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(), + __idx, __base); } + + inline long long + stoll(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(), + __idx, __base); } + + inline unsigned long long + stoull(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(), + __idx, __base); } + + // NB: wcstof vs wcstod. + inline float + stof(const __wvstring& __str, std::size_t* __idx = 0) + { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); } + + inline double + stod(const __wvstring& __str, std::size_t* __idx = 0) + { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); } + + inline long double + stold(const __wvstring& __str, std::size_t* __idx = 0) + { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); } + + inline __wvstring + to_wstring(long long __val) + { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, + 4 * sizeof(long long), + L"%lld", __val); } + + inline __wvstring + to_wstring(unsigned long long __val) + { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, + 4 * sizeof(unsigned long long), + L"%llu", __val); } + + inline __wvstring + to_wstring(long double __val) + { + const int __n = __numeric_traits::__max_exponent10 + 20; + return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n, + L"%Lf", __val); + } +#endif + +_GLIBCXX_END_NAMESPACE + +#endif + #ifndef _GLIBCXX_EXPORT_TEMPLATE # include "vstring.tcc" #endif diff --git a/libstdc++-v3/src/Makefile.am b/libstdc++-v3/src/Makefile.am index fa1e7c8d427..f5d99c63525 100644 --- a/libstdc++-v3/src/Makefile.am +++ b/libstdc++-v3/src/Makefile.am @@ -182,7 +182,6 @@ sources = \ streambuf-inst.cc \ streambuf.cc \ string-inst.cc \ - string_conversions.cc \ valarray-inst.cc \ wlocale-inst.cc \ wstring-inst.cc \ @@ -279,11 +278,6 @@ atomic.lo: atomic.cc atomic.o: atomic.cc $(CXXCOMPILE) -x c++ -std=gnu++0x -c $< -string_conversions.lo: string_conversions.cc - $(LTCXXCOMPILE) -x c++ -std=gnu++0x -c $< -string_conversions.o: string_conversions.cc - $(CXXCOMPILE) -x c++ -std=gnu++0x -c $< - if GLIBCXX_LDBL_COMPAT # Use special rules for compatibility-ldbl.cc compilation, as we need to # pass -mlong-double-64. diff --git a/libstdc++-v3/src/Makefile.in b/libstdc++-v3/src/Makefile.in index 7cf3f90414e..508a399e7e8 100644 --- a/libstdc++-v3/src/Makefile.in +++ b/libstdc++-v3/src/Makefile.in @@ -83,12 +83,11 @@ am__libstdc___la_SOURCES_DIST = atomic.cc bitmap_allocator.cc \ allocator-inst.cc concept-inst.cc fstream-inst.cc ext-inst.cc \ ios-inst.cc iostream-inst.cc istream-inst.cc istream.cc \ locale-inst.cc misc-inst.cc ostream-inst.cc sstream-inst.cc \ - streambuf-inst.cc streambuf.cc string-inst.cc \ - string_conversions.cc valarray-inst.cc wlocale-inst.cc \ - wstring-inst.cc mutex.cc condition_variable.cc atomicity.cc \ - codecvt_members.cc collate_members.cc ctype_members.cc \ - messages_members.cc monetary_members.cc numeric_members.cc \ - time_members.cc basic_file.cc c++locale.cc \ + streambuf-inst.cc streambuf.cc string-inst.cc valarray-inst.cc \ + wlocale-inst.cc wstring-inst.cc mutex.cc condition_variable.cc \ + atomicity.cc codecvt_members.cc collate_members.cc \ + ctype_members.cc messages_members.cc monetary_members.cc \ + numeric_members.cc time_members.cc basic_file.cc c++locale.cc \ compatibility-ldbl.cc parallel_list.cc parallel_settings.cc am__objects_1 = atomicity.lo codecvt_members.lo collate_members.lo \ ctype_members.lo messages_members.lo monetary_members.lo \ @@ -109,8 +108,8 @@ am__objects_5 = atomic.lo bitmap_allocator.lo pool_allocator.lo \ fstream-inst.lo ext-inst.lo ios-inst.lo iostream-inst.lo \ istream-inst.lo istream.lo locale-inst.lo misc-inst.lo \ ostream-inst.lo sstream-inst.lo streambuf-inst.lo streambuf.lo \ - string-inst.lo string_conversions.lo valarray-inst.lo \ - wlocale-inst.lo wstring-inst.lo mutex.lo condition_variable.lo \ + string-inst.lo valarray-inst.lo wlocale-inst.lo \ + wstring-inst.lo mutex.lo condition_variable.lo \ $(am__objects_1) $(am__objects_4) am_libstdc___la_OBJECTS = $(am__objects_5) libstdc___la_OBJECTS = $(am_libstdc___la_OBJECTS) @@ -419,7 +418,6 @@ sources = \ streambuf-inst.cc \ streambuf.cc \ string-inst.cc \ - string_conversions.cc \ valarray-inst.cc \ wlocale-inst.cc \ wstring-inst.cc \ @@ -874,11 +872,6 @@ atomic.lo: atomic.cc atomic.o: atomic.cc $(CXXCOMPILE) -x c++ -std=gnu++0x -c $< -string_conversions.lo: string_conversions.cc - $(LTCXXCOMPILE) -x c++ -std=gnu++0x -c $< -string_conversions.o: string_conversions.cc - $(CXXCOMPILE) -x c++ -std=gnu++0x -c $< - # Use special rules for compatibility-ldbl.cc compilation, as we need to # pass -mlong-double-64. @GLIBCXX_LDBL_COMPAT_TRUE@compatibility-ldbl.lo: compatibility-ldbl.cc diff --git a/libstdc++-v3/src/string_conversions.cc b/libstdc++-v3/src/string_conversions.cc deleted file mode 100644 index ef402ea0c39..00000000000 --- a/libstdc++-v3/src/string_conversions.cc +++ /dev/null @@ -1,199 +0,0 @@ -// String Conversions -*- C++ -*- - -// Copyright (C) 2008 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, -// USA. - -// As a special exception, you may use this file as part of a free software -// library without restriction. Specifically, if other files instantiate -// templates or use macros or inline functions from this file, or you compile -// this file and link it with other files to produce an executable, this -// file does not by itself cause the resulting executable to be covered by -// the GNU General Public License. This exception does not however -// invalidate any other reasons why the executable file might be covered by -// the GNU General Public License. - -#include -#include -#include -#include -#include - -#ifdef _GLIBCXX_USE_C99 - -_GLIBCXX_BEGIN_NAMESPACE(std) - - // Helper for all the sto* functions. - template - inline _Ret - __stoa(_TRet (*__convf) (const _CharT*, _CharT**, _Base...), - const char* __name, const basic_string<_CharT>& __str, - size_t* __idx, _Base... __base) - { - _Ret __ret; - - _CharT* __endptr; - errno = 0; - const _TRet __tmp = __convf(__str.c_str(), &__endptr, __base...); - - if (__endptr == __str.c_str()) - __throw_invalid_argument(__name); - else if (errno == ERANGE - || (__are_same<_Ret, int>::__value - && (__tmp < numeric_limits<_Ret>::min() - || __tmp > numeric_limits<_Ret>::max()))) - __throw_out_of_range(__name); - else - __ret = __tmp; - - if (__idx) - *__idx = __endptr - __str.c_str(); - - return __ret; - } - - // Helper for the to_string / to_wstring functions. - template - inline basic_string<_CharT> - __to_xstring(int (*__convf) (_CharT*, size_t, const _CharT*, va_list), - size_t __n, const _CharT* __fmt, ...) - { - // XXX Eventually the result will be constructed in place in - // the C++0x string, likely with the help of internal hooks. - _CharT* __s = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) - * __n)); - - va_list __args; - va_start(__args, __fmt); - - const int __len = __convf(__s, __n, __fmt, __args); - - va_end(__args); - - return basic_string<_CharT>(__s, __s + __len); - } - - - int - stoi(const string& __str, size_t* __idx, int __base) - { return std::__stoa(&std::strtol, "stoi", __str, - __idx, __base); } - - long - stol(const string& __str, size_t* __idx, int __base) - { return std::__stoa(&std::strtol, "stol", __str, __idx, __base); } - - unsigned long - stoul(const string& __str, size_t* __idx, int __base) - { return std::__stoa(&std::strtoul, "stoul", __str, __idx, __base); } - - long long - stoll(const string& __str, size_t* __idx, int __base) - { return std::__stoa(&std::strtoll, "stoll", __str, __idx, __base); } - - unsigned long long - stoull(const string& __str, size_t* __idx, int __base) - { return std::__stoa(&std::strtoull, "stoull", __str, __idx, __base); } - - // NB: strtof vs strtod. - float - stof(const string& __str, size_t* __idx) - { return std::__stoa(&std::strtof, "stof", __str, __idx); } - - double - stod(const string& __str, size_t* __idx) - { return std::__stoa(&std::strtod, "stod", __str, __idx); } - - long double - stold(const string& __str, size_t* __idx) - { return std::__stoa(&std::strtold, "stold", __str, __idx); } - - // NB: (v)snprintf vs sprintf. - string - to_string(long long __val) - { return std::__to_xstring(&std::vsnprintf, 4 * sizeof(long long), - "%lld", __val); } - - string - to_string(unsigned long long __val) - { return std::__to_xstring(&std::vsnprintf, 4 * sizeof(unsigned long long), - "%llu", __val); } - - string - to_string(long double __val) - { - const int __n = numeric_limits::max_exponent10 + 20; - return std::__to_xstring(&std::vsnprintf, __n, "%Lf", __val); - } - -#ifdef _GLIBCXX_USE_WCHAR_T - int - stoi(const wstring& __str, size_t* __idx, int __base) - { return std::__stoa(&std::wcstol, "stoi", __str, - __idx, __base); } - - long - stol(const wstring& __str, size_t* __idx, int __base) - { return std::__stoa(&std::wcstol, "stol", __str, __idx, __base); } - - unsigned long - stoul(const wstring& __str, size_t* __idx, int __base) - { return std::__stoa(&std::wcstoul, "stoul", __str, __idx, __base); } - - long long - stoll(const wstring& __str, size_t* __idx, int __base) - { return std::__stoa(&std::wcstoll, "stoll", __str, __idx, __base); } - - unsigned long long - stoull(const wstring& __str, size_t* __idx, int __base) - { return std::__stoa(&std::wcstoull, "stoull", __str, __idx, __base); } - - // NB: wcstof vs wcstod. - float - stof(const wstring& __str, size_t* __idx) - { return std::__stoa(&std::wcstof, "stof", __str, __idx); } - - double - stod(const wstring& __str, size_t* __idx) - { return std::__stoa(&std::wcstod, "stod", __str, __idx); } - - long double - stold(const wstring& __str, size_t* __idx) - { return std::__stoa(&std::wcstold, "stold", __str, __idx); } - - wstring - to_wstring(long long __val) - { return std::__to_xstring(&std::vswprintf, 4 * sizeof(long long), - L"%lld", __val); } - - wstring - to_wstring(unsigned long long __val) - { return std::__to_xstring(&std::vswprintf, 4 * sizeof(unsigned long long), - L"%llu", __val); } - - wstring - to_wstring(long double __val) - { - const int __n = numeric_limits::max_exponent10 + 20; - return std::__to_xstring(&std::vswprintf, __n, L"%Lf", __val); - } -#endif - -_GLIBCXX_END_NAMESPACE - -#endif