<HTML><HEAD><TITLE>N1803=05-0063, Simple Numeric Access</TITLE></HEAD><BODY>

<CENTER>
<H1><A NAME="Simple Numeric Access">Simple Numeric Access</A></H1>
</CENTER>

<TABLE ALIGN="RIGHT" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD ALIGN="RIGHT"><B><I>Document number:</I></B></TD>
<TD>&nbsp; N1803=05-0063</TD>
</TR>
<TR>
<TD ALIGN="RIGHT"><B><I>Date:</I></B></TD>
<TD>&nbsp; 2005-04-18</TD>
</TR>
<TR>
<TD ALIGN="RIGHT"><B><I>Project:</I></B></TD>
<TD>&nbsp; Programming Language C++</TD>
</TR>
<TR>
<TD ALIGN="RIGHT"><B><I>Reference:</I></B></TD>
<TD>&nbsp; ISO/IEC IS 14882:2003(E)</TD>
</TR>
<TR>
<TD ALIGN="RIGHT"><B><I>Reply to:</I></B></TD>
<TD>&nbsp; Pete Becker</TD>
</TR>
<TR>
<TD></TD>
<TD>&nbsp; Dinkumware, Ltd.</TD>
</TR>
<TR>
<TD></TD>
<TD>&nbsp; petebecker@acm.org</TD>
</TR>
</TABLE>
<BR CLEAR="ALL">

<HR>

<H2><A NAME=Proposed Wording>Proposed Wording</H2>

<P>Add the following to [lib.string.classes] at the end of the "Header &lt;string&gt;
synopsis":</P>

<BLOCKQUOTE>
<CODE><PRE>int stoi(string&amp; str, int base = 10);
long stol(string&amp; str, int base = 10);
unsigned long stoul(string&amp; str, int base = 10);
long long stoll(string&amp; str, int base = 10);
unsigned long long stoull(string&amp; str, int base = 10);
float stof(string&amp; str);
double stod(string&amp; str);
long double stold(string&amp; str);
string to_string(long long val);
string to_string(unsigned long long val);
string to_string(long double val);</CODE></PRE>
</BLOCKQUOTE>

Add the following as a new subclause 21.3.7.10, "Numeric conversions":

<BLOCKQUOTE>
<PRE><CODE>int stoi(string&amp; str, int base = 10);
long stol(string&amp; str, int base = 10);
unsigned long stoul(string&amp; str, int base = 10);
long long stoll(string&amp; str, int base = 10);
unsigned long long stoull(string&amp; str, int base = 10);</CODE></PRE>

<P><I>Effects:</I> the first two functions call <CODE>strtol(str.c_str(), 0, base)</CODE>,
and the last three functions call <CODE>strtoul(str.c_str(), 0, base)</CODE>,
<CODE>strtoll(str.c_str(), 0, base)</CODE>,
and <CODE>strtoull(str.c_str(), 0, base)</CODE>, respectively. Each
returns the converted result, if any, and erases the characters from the front of
<CODE>str</CODE> that were converted to get the result.</P>

<P><I>Returns:</I> the converted result.</P>

<P><I>Throws:</I> <CODE>invalid_argument</CODE> if <CODE>strol</CODE>, <CODE>strtoul</CODE>,
<CODE>strtoll</CODE>, or <CODE>strtoull</CODE> reports that no conversion could be performed.
Throws <CODE>out_of_range</CODE> if the converted value is outside the range of representable
values for the return type.</P>

<PRE><CODE>float stof(string&amp; str);
double stod(string&amp; str);
long double stold(string&amp; str);</CODE></PRE>

<P><I>Effects:</I> the functions call <CODE>strtof(str.c_str(), 0)</CODE>,
<CODE>strtod(str.c_str(), 0)</CODE>,
and <CODE>strtold(str.c_str(), 0)</CODE>, respectively, and
return the converted result, if any. They erase the characters from the front of
<CODE>str</CODE> that were converted to get the result.</P>

<P><I>Returns:</I> the converted result.</P>

<P><I>Throws:</I> <CODE>invalid_argument</CODE> if <CODE>strof</CODE>, <CODE>strtod</CODE>,
or <CODE>strtold</CODE> reports that no conversion could be performed.
Throws <CODE>out_of_range</CODE> if <CODE>strtof</CODE>, <CODE>strtod</CODE>, or
<CODE>strtold</CODE> sets <CODE>errno</CODE> to <CODE>ERANGE</CODE>.</P>

<PRE><CODE>string to_string(long long val);
string to_string(unsigned long long val);
string to_string(long double val);</CODE></PRE>

<P><I>Returns:</I> each function returns a <CODE>string</CODE> object holding the
character representation of the value of its argument that would be generated by calling
<CODE>sprintf(buf, fmt, val)</CODE> with a format specifier of
<CODE>&quot;%lld&quot;</CODE>, <CODE>&quot;%ulld&quot;</CODE>, or
<CODE>&quot;%f&quot;</CODE>, respectively.</P>

<P><I>Throws:</I> nothing.</P>

</BLOCKQUOTE>

<HR>

</BODY></HTML>
