Commit a4ecd144 by Paolo Carlini Committed by Paolo Carlini

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
parent 0bc1b77f
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.
......
......@@ -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 =
......
......@@ -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;
......
// { 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;
}
// { 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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment