<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2124: Seed sequence over-specified</title>
<meta property="og:title" content="Issue 2124: Seed sequence over-specified">
<meta property="og:description" content="C++ library issue. Status: NAD">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2124.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#NAD">NAD</a> status.</em></p>
<h3 id="2124"><a href="lwg-closed.html#2124">2124</a>. Seed sequence over-specified</h3>
<p><b>Section:</b> 29.5.3.2 <a href="https://wg21.link/rand.req.seedseq">[rand.req.seedseq]</a> <b>Status:</b> <a href="lwg-active.html#NAD">NAD</a>
 <b>Submitter:</b> Alberto Ganesh Barbati <b>Opened:</b> 2012-01-16 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#rand.req.seedseq">issues</a> in [rand.req.seedseq].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#NAD">NAD</a> status.</p>
<p><b>Discussion:</b></p>

<p>
The seed sequence requirements described in 29.5.3.2 <a href="https://wg21.link/rand.req.seedseq">[rand.req.seedseq]</a> appear to be over-specified. 
All seed sequence types are required to have a <code>result_type</code> nested type, a specific set of 
constructors, function members <code>size()</code> and <code>param()</code>, which are never used by the library. 
In fact, the only library components that actively use seed sequences are the random engines and all the 
engines need is the <code>generate()</code> member function. In particular, library components never attempts 
to construct seed sequence objects. These extraneous requirements are clearly written to describe the 
library provided type <code>seed_seq</code> type; while it's good that seed_seq has all those constructors and 
members, it's not a compelling reason to require a user-provided seed sequence type to implement all of 
them.
<p/>
Suppose I want to write my own seed sequence class, this should do fine (and actually works as expected with libc++):
</p>
<blockquote><pre>
class my_seed_seq
{
  /* internals */
public:
  my_seed_seq(/* my own parameters */);

  template &lt;class It&gt;
  void generate(It first, It last);
};

my_seed_seq s(/* params */);
std::default_random_engine e(s);
</pre></blockquote>
<p>
The only reason to have these extra members would be to provide some support for generic serializability&#47;persistence 
of seed sequence objects. I believe that would be out of the scope of the random library, so I doubt we will ever need 
those requirements in the future.
<p/>
I therefore propose to remove all requirements from 29.5.3.2 <a href="https://wg21.link/rand.req.seedseq">[rand.req.seedseq]</a> except for the presence of the 
<code>generate()</code> function.
</p>

<p><i>[2012, Kona]</i></p>

<p>
Move to Tenatively NAD.  (Tentative as issue was not in pre-meeting mailing)
</p>
<p>
The 'overspecification', as such, was a deliberate intent to provide guarantees consumers of the whole
random number framework may rely upon, especially in generic code.  While the standard engines may be
built without relying on these guarantees, this specification is part of a commitment to a broader
framework, and Walter indicated future proposals in preparation for parallel generation of random
numbers that may depend more inimately on these existing requirements.
</p>
<p>
Alisdair noted that the <code>result_type</code> typedef was a call-back to how we used to specify
adaptable functors before TR1 <code>result_of</code> and the addition of <code>std::bind</code> and is
probably not something we should be actively promoting in future libraries.  However, it is too
late to remove this requirement from seed sequences unless we are doing further surgery, as
recommended by this issue.
</p>
<p>
Walter notes that the <code>result_type</code> protocol has not been formally deprecated by the
standard.  Alisdair replies that was the intent of deprecating the <code>bind_1st</code>/
<code>unary_function</code> set of templates in C++11, although we did not say anything about
<code>result_type</code> in general.
</p>



<p id="res-2124"><b>Proposed resolution:</b></p>
<p>This wording is relative to the FDIS.</p>

<ol>
<li>
<p>Edit 29.5.3.2 <a href="https://wg21.link/rand.req.seedseq">[rand.req.seedseq]</a> p2 as indicated:</p>

<blockquote><p>
A class <code>S</code> satisfies the requirements of a seed sequence if the expressions shown in Table 115 are valid and
have the indicated semantics, and if <code>S</code> also satisfies all other requirements of this section 29.5.3.2 <a href="https://wg21.link/rand.req.seedseq">[rand.req.seedseq]</a>. 
In that Table and throughout this section:
</p>
<ol style="list-style-type:lower-alpha">
<li>
<del><code>T</code> is the type named by <code>S</code>'s associated <code>result_type</code>;</del>
</li>
<li>
<code>q</code> is a value of <code>S</code><del> and <code>r</code> is a possibly const value of <code>S</code></del>; <ins>and</ins>
</li>
<li>
<del><code>ib</code> and <code>ie</code> are input iterators with an unsigned integer <code>value_type</code> of at least 32 bits;</del>
</li>
<li><code>rb</code> and <code>re</code> are mutable random access iterators with an unsigned integer <code>value_type</code> of at least 32 bits;</li>
<li>
<del><code>ob</code> is an output iterator; and</del>
</li>
<li>
<del><code>il</code> is a value of <code>initializer_list&lt;T&gt;</code>.</del>
</li>
</ol>
</blockquote>
</li>

<li>
<p>Ditto, in Table 115, remove all rows except the one describing <code>q.generate(rb, re)</code>:</p>

<table border="1">
<caption>Table 115 &mdash; Seed sequence requirements</caption>
<tr align="center">
<th>Expression</th>
<th>Return type</th>
<th>Pre&#47;Post-condition</th>
<th>Complexity</th>
</tr> 

<tr>
<td>
<del><code>S::result_type</code></del>
</td>
<td>
<del><code>T</code></del>
</td>
<td>
<del><code>T</code> is an unsigned integer<br/>
type (6.9.2 <a href="https://wg21.link/basic.fundamental">[basic.fundamental]</a>) of at least 32 bits.</del>
</td>
<td>
<del>compile-time</del>
</td>
</tr>

<tr>
<td>
<del><code>S()</code></del>
</td>
<td>
&nbsp;
</td>
<td>
<del>Creates a seed sequence with<br/>
the same initial state as all<br/>
other default-constructed seed<br/>
sequences of type <code>S</code>.</del>
</td>
<td>
<del>constant</del>
</td>
</tr>

<tr>
<td>
<del><code>S(ib,ie)</code></del>
</td>
<td>
&nbsp;
</td>
<td>
<del>Creates a seed sequence having<br/>
internal state that depends on<br/>
some or all of the bits of the<br/>
supplied sequence <code>[ib, ie)</code>.</del>
</td>
<td>
<del><code>&#x1d4aa;(ie - ib)</code></del>
</td>
</tr>

<tr>
<td>
<del><code>S(il)</code></del>
</td>
<td>
&nbsp;
</td>
<td>
<del>Same as <code>S(il.begin(),<br/>
il.end())</code>.</del>
</td>
<td>
<del>same as<br/>
<code>S(il.begin(),<br/>
il.end())</code></del>
</td>
</tr>

<tr>
<td>
<code>q.generate(rb,re)</code>
</td>
<td>
<code>void</code>
</td>
<td>
Does nothing if <code>rb == re</code>.<br/>
Otherwise, fills the supplied<br/>
sequence <code>[rb, re)</code> with 32-bit<br/>
quantities that depend on the<br/>
sequence supplied to the<br/>
constructor and possibly also<br/>
depend on the history of<br/>
<code>generate</code>'s previous<br/>
invocations.
</td>
<td>
<code>&#x1d4aa;(re - rb)</code>
</td>
</tr>

<tr>
<td>
<del><code>r.size()</code></del>
</td>
<td>
<del><code>size_t</code></del>
</td>
<td>
<del>The number of 32-bit units that<br/>
would be copied by a call to<br/>
<code>r.param</code>.</del>
</td>
<td>
<del>constant</del>
</td>
</tr>

<tr>
<td>
<del><code>r.param(ob)</code></del>
</td>
<td>
<del><code>void</code></del>
</td>
<td>
<del>Copies to the given destination
a sequence of 32-bit units that<br/>
can be provided to the<br/>
constructor of a second object<br/>
of type <code>S</code>, and that would<br/>
reproduce in that second object<br/>
a state indistinguishable from<br/>
the state of the first object.</del>
</td>
<td>
<del><code>&#x1d4aa;(r.size())</code></del>
</td>
</tr>

</table>
 </li>

</ol>






</body>
</html>
