aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2009-11-11 19:57:48 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2009-11-11 19:57:48 +0000
commita4ecd144bb7cbad8f122f98b2db8a3b6de468361 (patch)
tree39b13993ddc2e135fa9d6a504906c8e16036c5a9
parent0bc1b77f3219f3f8038fcc34f13eddc08ba86ce8 (diff)
downloadgcc-a4ecd144bb7cbad8f122f98b2db8a3b6de468361.zip
gcc-a4ecd144bb7cbad8f122f98b2db8a3b6de468361.tar.gz
gcc-a4ecd144bb7cbad8f122f98b2db8a3b6de468361.tar.bz2
basic_string.h (to_string(int), [...]): Add, per resolution of DR 1261.
2009-11-11 Paolo Carlini <paolo.carlini@oracle.com> * include/bits/basic_string.h (to_string(int), to_string(unsigned), to_string(long), to_string(unsigned long), to_string(float), to_string(double), to_wstring(int), to_wstring(unsigned), to_wstring(long), to_wstring(unsigned long), to_wstring(float), to_wstring(double)): Add, per resolution of DR 1261. * include/ext/vstring.h: Likewise. * testsuite/21_strings/basic_string/numeric_conversions/char/ dr1261.cc: Add. * testsuite/21_strings/basic_string/numeric_conversions/wchar_t/ dr1261.cc: Likewise. From-SVN: r154102
-rw-r--r--libstdc++-v3/ChangeLog13
-rw-r--r--libstdc++-v3/include/bits/basic_string.h83
-rw-r--r--libstdc++-v3/include/ext/vstring.h83
-rw-r--r--libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/dr1261.cc65
-rw-r--r--libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/dr1261.cc65
5 files changed, 309 insertions, 0 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 154d4d5..b34122c 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,16 @@
+2009-11-11 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * include/bits/basic_string.h (to_string(int), to_string(unsigned),
+ to_string(long), to_string(unsigned long), to_string(float),
+ to_string(double), to_wstring(int), to_wstring(unsigned),
+ to_wstring(long), to_wstring(unsigned long), to_wstring(float),
+ to_wstring(double)): Add, per resolution of DR 1261.
+ * include/ext/vstring.h: Likewise.
+ * testsuite/21_strings/basic_string/numeric_conversions/char/
+ dr1261.cc: Add.
+ * testsuite/21_strings/basic_string/numeric_conversions/wchar_t/
+ dr1261.cc: Likewise.
+
2009-11-09 Benjamin Kosnik <bkoz@redhat.com>
* doc/doxygen/user.cfg.in: Regenerate, add files.
diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h
index 9d44dc4..269a75e 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -2639,6 +2639,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,
@@ -2652,6 +2676,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 =
@@ -2699,6 +2741,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,
@@ -2712,6 +2777,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 =
diff --git a/libstdc++-v3/include/ext/vstring.h b/libstdc++-v3/include/ext/vstring.h
index 61e6ae4..183d037 100644
--- a/libstdc++-v3/include/ext/vstring.h
+++ b/libstdc++-v3/include/ext/vstring.h
@@ -2464,6 +2464,32 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
{ return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); }
// NB: (v)snprintf vs sprintf.
+
+ // DR 1261.
+ inline __vstring
+ to_string(int __val)
+ { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 4 * sizeof(int),
+ "%d", __val); }
+
+ inline __vstring
+ to_string(unsigned __val)
+ { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
+ 4 * sizeof(unsigned),
+ "%u", __val); }
+
+ inline __vstring
+ to_string(long __val)
+ { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
+ 4 * sizeof(long),
+ "%ld", __val); }
+
+ inline __vstring
+ to_string(unsigned long __val)
+ { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
+ 4 * sizeof(unsigned long),
+ "%lu", __val); }
+
+
inline __vstring
to_string(long long __val)
{ return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
@@ -2477,6 +2503,22 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
"%llu", __val); }
inline __vstring
+ to_string(float __val)
+ {
+ const int __n = __numeric_traits<float>::__max_exponent10 + 20;
+ return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
+ "%f", __val);
+ }
+
+ inline __vstring
+ to_string(double __val)
+ {
+ const int __n = __numeric_traits<double>::__max_exponent10 + 20;
+ return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
+ "%f", __val);
+ }
+
+ inline __vstring
to_string(long double __val)
{
const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
@@ -2524,6 +2566,31 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
{ return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); }
#ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
+ // DR 1261.
+ inline __wvstring
+ to_wstring(int __val)
+ { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
+ 4 * sizeof(int),
+ L"%d", __val); }
+
+ inline __wvstring
+ to_wstring(unsigned __val)
+ { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
+ 4 * sizeof(unsigned),
+ L"%u", __val); }
+
+ inline __wvstring
+ to_wstring(long __val)
+ { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
+ 4 * sizeof(long),
+ L"%ld", __val); }
+
+ inline __wvstring
+ to_wstring(unsigned long __val)
+ { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
+ 4 * sizeof(unsigned long),
+ L"%lu", __val); }
+
inline __wvstring
to_wstring(long long __val)
{ return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
@@ -2537,6 +2604,22 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
L"%llu", __val); }
inline __wvstring
+ to_wstring(float __val)
+ {
+ const int __n = __numeric_traits<float>::__max_exponent10 + 20;
+ return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
+ L"%f", __val);
+ }
+
+ inline __wvstring
+ to_wstring(double __val)
+ {
+ const int __n = __numeric_traits<double>::__max_exponent10 + 20;
+ return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
+ L"%f", __val);
+ }
+
+ inline __wvstring
to_wstring(long double __val)
{
const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/dr1261.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/dr1261.cc
new file mode 100644
index 0000000..739ceed
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/dr1261.cc
@@ -0,0 +1,65 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-string-conversions "" }
+
+// 2009-11-11 Paolo Carlini <paolo.carlini@oracle.com>
+
+// Copyright (C) 2009 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+#include <string>
+#include <testsuite_hooks.h>
+
+// DR 1261. Insufficient overloads for to_string / to_wstring
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+
+ const string one(to_string(-2));
+ VERIFY( one == "-2" );
+
+ const string two(to_string(10u));
+ VERIFY( two == "10" );
+
+ const string three(to_string(2l));
+ VERIFY( three == "2" );
+
+ const string four(to_string(3000ul));
+ VERIFY( four == "3000" );
+
+ const string five(to_string(7ll));
+ VERIFY( five == "7" );
+
+ const string six(to_string(400ull));
+ VERIFY( six == "400" );
+
+ const string seven(to_string(-1.0F));
+ VERIFY( seven == "-1.000000" );
+
+ const string eight(to_string(2.0));
+ VERIFY( eight == "2.000000" );
+
+ const string nine(to_string(-4.0L));
+ VERIFY( nine == "-4.000000" );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/dr1261.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/dr1261.cc
new file mode 100644
index 0000000..7d754b3
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/dr1261.cc
@@ -0,0 +1,65 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-string-conversions "" }
+
+// 2009-11-11 Paolo Carlini <paolo.carlini@oracle.com>
+
+// Copyright (C) 2009 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+#include <string>
+#include <testsuite_hooks.h>
+
+// DR 1261. Insufficient overloads for to_string / to_wstring
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+
+ const wstring one(to_wstring(-2));
+ VERIFY( one == L"-2" );
+
+ const wstring two(to_wstring(10u));
+ VERIFY( two == L"10" );
+
+ const wstring three(to_wstring(2l));
+ VERIFY( three == L"2" );
+
+ const wstring four(to_wstring(3000ul));
+ VERIFY( four == L"3000" );
+
+ const wstring five(to_wstring(7ll));
+ VERIFY( five == L"7" );
+
+ const wstring six(to_wstring(400ull));
+ VERIFY( six == L"400" );
+
+ const wstring seven(to_wstring(-1.0F));
+ VERIFY( seven == L"-1.000000" );
+
+ const wstring eight(to_wstring(2.0));
+ VERIFY( eight == L"2.000000" );
+
+ const wstring nine(to_wstring(-4.0L));
+ VERIFY( nine == L"-4.000000" );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}