<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <meta name="Author" content="Robert Klarer">
   <title>J16/06-0165 = WG21/N2095 -- long long Goes to the Library</title>
</head>
<body>
<pre>
<br>
                                        Doc No:   SC22/WG21/N2095
                                                  J16/06-0165
                                        Date:     2006-09-07
                                        Project:  JTC1.22.32
                                        Reply to: Robert Klarer
                                                  IBM Canada, Ltd.
                                                  klarer@ca.ibm.com
</pre>

<h1>long long Goes to the Library</h1>

<p>
This paper proposes a small number of straightforward and probably uncontroversial changes to the Working Draft to complete integration of the <code>long long</code> and <code>unsigned long long</code> types with the C++ Standard Library.  
</p>
<p>
This paper does not propose changes to the specification of the <code>&lt;random></code> library for the simple reason that to do so would likely cause confusion.  Since the LWG has agreed in principle to <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1932.pdf">N1932, "Random Number Generation in C++0X: A Comprehensive Proposal,"</a> I think that it's prudent to wait until that proposal is formally approved and reconciled with the Working Draft before we attempt to patch it.
</p>
<p>
Among the changes proposed below is the addition of new virtual member functions (overloads of <code>do_get</code> and <code>do_put</code>) to the <code>num_get</code> and <code>num_put</code> facets.  Normally, the introduction of virtual functions to an existing class interface will pose backwards binary compatibility problems for implementers and, ultimately, programmers.  I believe, however, that these virtual functions are already implemented widely as conforming extensions, so I predict that no backwards incompatibility will result from the changes.
</p>


<h2>Proposed Working Draft changes</h2>
<h3>18.2.1 Numeric limits</h3>
<p>
add the following to "Header <limits> synopsis":
</p>

<pre>
        template&lt;> class numeric_limits&lt;long long>;
        template&lt;> class numeric_limits&lt;unsigned long long>;
</pre>

<h3>20.5 Function objects</h3>
<p>
add the following to "Header &lt;functional> synopsis":
</p>

<pre>
        template &lt;> struct hash&lt;long long>;
        template &lt;> struct hash&lt;unsigned long long>;
</pre>

<h3>
21.4 Null-terminated sequence utilities:
</h3>
<p>
add the following to "Table 63: Header &lt;cstdlib> synopsis":
</p>

<pre>
strtoull
</pre>

<h3>
22.2.2.1 Class template num_get
</h3>
<p>
add the following public member functions to the class definition:
</p>

<pre>
        iter_type get(iter_type <i>in</i>, iter_type <i>end</i>, ios_base&amp;,
                      ios_base::iostate&amp; <i>err</i>, long long&amp; <i>v</i>)          const;
        iter_type get(iter_type <i>in</i>, iter_type <i>end</i>, ios_base&amp;,
                      ios_base::iostate&amp; <i>err</i>, unsigned long long&amp; <i>v</i>) const;
</pre>

<p>
add the following protected member functions to the class definition:
</p>

<pre>
        virtual iter_type do_get(iter_type in, iter_type end, ios_base&amp;,
                                 ios_base::iostate&amp; err, long long&amp; v)          const;
        virtual iter_type do_get(iter_type in, iter_type end, ios_base&amp;,
                                 ios_base::iostate&amp; err, unsigned long long&amp; v) const;
</pre>

<h3>
22.2.2.1.1 num_get members
</h3>
<p>
add the following:
</p>

<pre>
        iter_type get(iter_type <i>in</i>, iter_type <i>end</i>, ios_base&amp; <i>str</i>,
                      ios_base::iostate&amp; <i>err</i>, long long&amp; <i>val</i>)          const;
        iter_type get(iter_type <i>in</i>, iter_type <i>end</i>, ios_base&amp; <i>str</i>,
                      ios_base::iostate&amp; <i>err</i>, unsigned long long&amp; <i>val</i>) const;
</pre>

<h3>
22.2.2.1.2 num_get virtual functions
</h3>
<p>
to the list of function declarations before paragraph 1, add the following:
</p>

<pre>
        iter_type do_get(iter_type <i>in</i>, iter_type <i>end</i>, ios_base&amp; <i>str</i>,
                         ios_base::iostate&amp; <i>err</i>, long long&amp; <i>val</i>)          const;
        iter_type do_get(iter_type <i>in</i>, iter_type <i>end</i>, ios_base&amp; <i>str</i>,
                         ios_base::iostate&amp; <i>err</i>, unsigned long long&amp; <i>val</i>) const;
</pre>

<p>
To "Table 70: Length Modifier," add the following rows:
</p>

<table border=1>
<tr>
<td>
<code>long long</code>
</td>
<td>
<code>ll</code>
</td>
</tr>
<tr>
<td>
<code>unsigned long long</code>
</td>
<td>
<code>ll</code>
</td>
</tr>
</table>

<h3>
22.2.2.2 Class template num_put
</h3>
<p>
add the following public member functions to the class definition:
</p>

<pre>
        iter_type put(iter_type <i>s</i>, ios_base&amp; <i>f</i>, char_type <i>fill</i>,
                      long long&amp; <i>v</i>)          const;
        iter_type put(iter_type <i>s</i>, ios_base&amp; <i>f</i>, char_type <i>fill</i>,
                      unsigned long long&amp; <i>v</i>) const;
</pre>

<p>
add the following protected member functions to the class definition:
</p>

<pre>
        virtual iter_type do_put(iter_type, ios_base&amp;, char_type <i>fill</i>,
                                 long long&amp; <i>v</i>)          const;
        virtual iter_type do_put(iter_type, ios_base&amp;, char_type <i>fill</i>,
                                 unsigned long long&amp; <i>v</i>) const;
</pre>

<h3>
22.2.2.2.1 num_put members
</h3>
<p>
to the list of function declarations before paragraph 1, add the following:
</p>

<pre>
        iter_type put(iter_type <i>out</i>, ios_base&amp; <i>str</i>, char_type <i>fill</i>,
                      long long&amp; <i>v</i>)          const;
        iter_type put(iter_type <i>out</i>, ios_base&amp; <i>str</i>, char_type <i>fill</i>,
                      unsigned long long&amp; <i>v</i>) const;
</pre>

<h3>
22.2.2.2.1 num_put virtual functions
</h3>
<p>
to the list of function declarations before paragraph 1, add the following:
<p>

<pre>
        iter_type do_put(iter_type <i>out</i>, ios_base&amp; <i>str</i>, char_type <i>fill</i>,
                         long long&amp; <i>v</i>)          const;
        iter_type do_put(iter_type <i>out</i>, ios_base&amp; <i>str</i>, char_type <i>fill</i>,
                         unsigned long long&amp; <i>v</i>) const;
</pre>

<p>
To "Table 73: Length Modifier," add the following rows:
</p>

<table border=1>
</tr>
<tr>
<td>
<code>long long</code>
</td>
<td>
<code>ll</code>
</td>
</tr>
<tr>
<td>
<code>unsigned long long</code>
</td>
<td>
<code>ll</code>
</td>
</tr>
</table>

<p>These rows should appear above the row that reads "<i>otherwise</i>/<i>none</i>."

<h3>
27.6.1.1 Class template basic_istream
</h3>

<p>
Add the following formatted input operators to the class synopsis:
</p>

<pre>
        // 27.6.1.2 Formatted input:
        ...
        basic_istream&lt;charT, traits>&amp; operator>>(long long&amp; <i>n</i>);
        basic_istream&lt;charT, traits>&amp; operator>>(unsigned long long&amp; <i>n</i>);
</pre>

<h3>
27.6.1.2.2 Arithmetic Extractors
</h3>
<p>
Add the following formatted input operators above paragraph 1:
</p>

<pre>
        operator>>(long long&amp; <i>val</i>);
        operator>>(unsigned long long&amp; <i>val</i>);
</pre>

<h3>
27.6.2.1 Class template basic_ostream
</h3>
<p>
Add the following formatted input operators to the class synopsis:
</p>

<pre>
        // 27.6.2.5 Formatted output:
        ...
        basic_ostream&lt;charT, traits>&amp; operator&lt;&lt;(long long <i>n</i>);
        basic_ostream&lt;charT, traits>&amp; operator&lt;&lt;(unsigned long long <i>n</i>);
</pre>

<h3>
27.6.2.5 Arithmetic Inserters
</h3>
<p>
Add the following formatted output operators above paragraph 1:
</p>

<pre>
        operator&lt;&lt;(long long <i>val</i>);
        operator&lt;&lt;(unsigned long long <i>val</i>);
</pre>
<p>
end of paper.
</p>

</body>
</html>
