<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1436: Random number engine constructor concerns</title>
<meta property="og:title" content="Issue 1436: Random number engine constructor concerns">
<meta property="og:description" content="C++ library issue. Status: C++11">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1436.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#C++11">C++11</a> status.</em></p>
<h3 id="1436"><a href="lwg-defects.html#1436">1436</a>. Random number engine constructor concerns</h3>
<p><b>Section:</b> 29.5.4 <a href="https://wg21.link/rand.eng">[rand.eng]</a> <b>Status:</b> <a href="lwg-active.html#C++11">C++11</a>
 <b>Submitter:</b> BSI <b>Opened:</b> 2010-08-25 <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.eng">issues</a> in [rand.eng].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++11">C++11</a> status.</p>
<p><b>Discussion:</b></p>
<p><b>Addresses GB-121</b></p>

<p>
All the random number engine types in this clause have a
constructor taking an unsigned integer type, and a
constructor template for seed sequences. This means that
an attempt to create a random number engine seeded by
an integer literal must remember to add the appropriate
unsigned suffix to the literal, as a signed integer will
attempt to use the seed sequence template, yielding
undefined behaviour, as per 26.5.1.1p1a. It would be
helpful if at least these anticipated cases produced a
defined behaviour, either an erroneous program with
diagnostic, or a conversion to unsigned int forwarding to
the appropriate constructor.
</p>

<p><i>[
2010-11-03 Daniel comments and provides a proposed resolution:
]</i></p>


<p>
I suggest to apply a similar solution as recently suggested for <a href="lwg-defects.html#1234" title="&quot;Do the right thing&quot; and NULL (Status: C++11)">1234</a><sup><a href="https://cplusplus.github.io/LWG/issue1234" title="Latest snapshot">(i)</a></sup>.
It is basically a requirement for an implementation to constrain the template.
</p>

<p><i>[
2010-11-04 Howard suggests to use <code>!is_convertible&lt;Sseq, result_type&gt;::value</code>
as minimum requirement instead of the originally proposed <code>!is_scalar&lt;Sseq&gt;::value</code>.
This would allow for a user-defined type <code>BigNum</code>, that is convertible to <code>result_type</code>,
to be used as argument for a seed instead of a seed sequence. The wording has been updated to 
reflect this suggestion.
]</i></p>


<p><i>[
2010 Batavia: There were some initial concerns regarding the portability and reproducibility of results 
when seeded with a negative signed value, but these concerns were allayed after discussion. Thus, after
reviewing the issue, the working group concurred with the issue's Proposed Resolution. 
]</i></p>


<p><i>[
Adopted at 2010-11 Batavia
]</i></p>




<p id="res-1436"><b>Proposed resolution:</b></p>
<p>
Add the following paragraph at the end of 29.5.4 <a href="https://wg21.link/rand.eng">[rand.eng]</a>:
</p>
<blockquote>
<blockquote><p>
5 Each template specified in this section [rand.eng] requires one or more relationships, involving the value(s) of
its non-type template parameter(s), to hold. A program instantiating any of these templates is ill-formed if
any such required relationship fails to hold.
</p></blockquote>

<blockquote><p>
<ins>? For every random number engine and for every random number engine adaptor <code>X</code> defined in this sub-clause 
[rand.eng] and in sub-clause [rand.adapt]:</ins></p>
<ul>
<li><ins>If the constructor</ins>
<blockquote><pre>
<ins>template&lt;class Sseq&gt; explicit X(Sseq&amp; q);</ins>
</pre></blockquote><p>
<ins>is called with a type <code>Sseq</code> that does not qualify as a seed sequence, then this constructor 
shall not participate in overload resolution.
</ins></p>
</li>
<li><ins>If the member function</ins>
<blockquote><pre>
<ins>template&lt;class Sseq&gt; void seed(Sseq&amp; q);</ins>
</pre></blockquote><p>
<ins>is called with a type <code>Sseq</code> that does not qualify as a seed sequence, then this function 
shall not participate in overload resolution.
</ins></p>
</li>
</ul>
<p>
<ins>The extent to which an implementation determines that a type cannot be a seed sequence is unspecified,
except that as a minimum a type shall not qualify as seed sequence, if it is implicitly convertible
to <code>X::result_type</code>.</ins>
</p>
</blockquote>

</blockquote>





</body>
</html>
