aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/src
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2008-06-16 09:58:54 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2008-06-16 09:58:54 +0000
commit7364f2868c8ac21e519725d716bc13f02b19684f (patch)
tree8685abf3ce961673fcc9761e7fded8aeef7e1b6a /libstdc++-v3/src
parent1b4b3957d77c7d12df446508b42f82bdaf8da8c8 (diff)
downloadgcc-7364f2868c8ac21e519725d716bc13f02b19684f.zip
gcc-7364f2868c8ac21e519725d716bc13f02b19684f.tar.gz
gcc-7364f2868c8ac21e519725d716bc13f02b19684f.tar.bz2
basic_string.h (stod, [...]): Declare in C++0x mode.
2008-06-16 Paolo Carlini <paolo.carlini@oracle.com> * include/bits/basic_string.h (stod, stof, stoi, stol, stold, stoll, stoul, stoull, to_string, to_wstring): Declare in C++0x mode. * src/string_conversions.cc: Add. * src/Makefile.am: Update. * config/abi/pre/gnu.ver: Adjust exports. * src/Makefile.in: Regenerate. * testsuite/21_strings/basic_string/numeric_conversions/char/stod.cc: New. * testsuite/21_strings/basic_string/numeric_conversions/char/stof.cc: Likewise. * testsuite/21_strings/basic_string/numeric_conversions/char/stoi.cc: Likewise. * testsuite/21_strings/basic_string/numeric_conversions/char/stol.cc: Likewise. * testsuite/21_strings/basic_string/numeric_conversions/char/stold.cc: Likewise. * testsuite/21_strings/basic_string/numeric_conversions/char/stoll.cc: Likewise. * testsuite/21_strings/basic_string/numeric_conversions/char/stoul.cc: Likewise. * testsuite/21_strings/basic_string/numeric_conversions/char/stoull.cc: Likewise. * testsuite/21_strings/basic_string/numeric_conversions/char/ to_string.cc: Likewise. * testsuite/21_strings/basic_string/numeric_conversions/wchar_t/ stod.cc: New. * testsuite/21_strings/basic_string/numeric_conversions/wchar_t/ stof.cc: Likewise. * testsuite/21_strings/basic_string/numeric_conversions/wchar_t/ stoi.cc: Likewise. * testsuite/21_strings/basic_string/numeric_conversions/wchar_t/ stol.cc: Likewise. * testsuite/21_strings/basic_string/numeric_conversions/wchar_t/ stold.cc: Likewise. * testsuite/21_strings/basic_string/numeric_conversions/wchar_t/ stoll.cc: Likewise. * testsuite/21_strings/basic_string/numeric_conversions/wchar_t/ stoul.cc: Likewise. * testsuite/21_strings/basic_string/numeric_conversions/wchar_t/ stoull.cc: Likewise. * testsuite/21_strings/basic_string/numeric_conversions/wchar_t/ to_wstring.cc: Likewise. From-SVN: r136841
Diffstat (limited to 'libstdc++-v3/src')
-rw-r--r--libstdc++-v3/src/Makefile.am6
-rw-r--r--libstdc++-v3/src/Makefile.in21
-rw-r--r--libstdc++-v3/src/string_conversions.cc195
3 files changed, 215 insertions, 7 deletions
diff --git a/libstdc++-v3/src/Makefile.am b/libstdc++-v3/src/Makefile.am
index f5d99c6..fa1e7c8 100644
--- a/libstdc++-v3/src/Makefile.am
+++ b/libstdc++-v3/src/Makefile.am
@@ -182,6 +182,7 @@ sources = \
streambuf-inst.cc \
streambuf.cc \
string-inst.cc \
+ string_conversions.cc \
valarray-inst.cc \
wlocale-inst.cc \
wstring-inst.cc \
@@ -278,6 +279,11 @@ 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 508a399..7cf3f90 100644
--- a/libstdc++-v3/src/Makefile.in
+++ b/libstdc++-v3/src/Makefile.in
@@ -83,11 +83,12 @@ 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 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 \
+ 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 \
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 \
@@ -108,8 +109,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 valarray-inst.lo wlocale-inst.lo \
- wstring-inst.lo mutex.lo condition_variable.lo \
+ string-inst.lo string_conversions.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)
@@ -418,6 +419,7 @@ sources = \
streambuf-inst.cc \
streambuf.cc \
string-inst.cc \
+ string_conversions.cc \
valarray-inst.cc \
wlocale-inst.cc \
wstring-inst.cc \
@@ -872,6 +874,11 @@ 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
new file mode 100644
index 0000000..627ddfa
--- /dev/null
+++ b/libstdc++-v3/src/string_conversions.cc
@@ -0,0 +1,195 @@
+// 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 <string>
+#include <limits>
+#include <cerrno>
+#include <cstdlib>
+
+#ifdef _GLIBCXX_USE_C99
+
+_GLIBCXX_BEGIN_NAMESPACE(std)
+
+ // Helper for all the sto* functions.
+ template<typename _TRet, typename _Ret = _TRet, typename _CharT,
+ typename... _Base>
+ 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;
+ }
+
+
+ int
+ stoi(const string& __str, size_t* __idx, int __base)
+ { return std::__stoa<long, int>(&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); }
+
+ string
+ to_string(long long __val)
+ {
+ // XXX Eventually the result will be constructed in place in
+ // the C++0x string, likely with the help of internal hooks.
+ const int __n = 4 * sizeof(long long);
+ char* __s = static_cast<char*>(__builtin_alloca(__n));
+ return string(__s, __s + std::snprintf(__s, __n, "%lld", __val));
+ }
+
+ string
+ to_string(unsigned long long __val)
+ {
+ const int __n = 4 * sizeof(unsigned long long);
+ char* __s = static_cast<char*>(__builtin_alloca(__n));
+ return string(__s, __s + std::snprintf(__s, __n, "%llu", __val));
+ }
+
+ string
+ to_string(long double __val)
+ {
+ const int __n = numeric_limits<long double>::max_exponent10 + 20;
+ char* __s = static_cast<char*>(__builtin_alloca(__n));
+ return string(__s, __s + std::snprintf(__s, __n, "%Lf", __val));
+ }
+
+#ifdef _GLIBCXX_USE_WCHAR_T
+ int
+ stoi(const wstring& __str, size_t* __idx, int __base)
+ { return std::__stoa<long, int>(&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)
+ {
+ const int __n = 4 * sizeof(long long);
+ wchar_t* __s = static_cast<wchar_t*>(__builtin_alloca(sizeof(wchar_t)
+ * __n));
+ return wstring(__s, __s + std::swprintf(__s, __n, L"%lld", __val));
+ }
+
+ wstring
+ to_wstring(unsigned long long __val)
+ {
+ const int __n = 4 * sizeof(unsigned long long);
+ wchar_t* __s = static_cast<wchar_t*>(__builtin_alloca(sizeof(wchar_t)
+ * __n));
+ return wstring(__s, __s + std::swprintf(__s, __n, L"%llu", __val));
+ }
+
+ wstring
+ to_wstring(long double __val)
+ {
+ const int __n = numeric_limits<long double>::max_exponent10 + 20;
+ wchar_t* __s = static_cast<wchar_t*>(__builtin_alloca(sizeof(wchar_t)
+ * __n));
+ return wstring(__s, __s + std::swprintf(__s, __n, L"%Lf", __val));
+ }
+#endif
+
+_GLIBCXX_END_NAMESPACE
+
+#endif