<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3422: Issues of seed_seq's constructors</title>
<meta property="og:title" content="Issue 3422: Issues of seed_seq's constructors">
<meta property="og:description" content="C++ library issue. Status: C++23">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3422.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++23">C++23</a> status.</em></p>
<h3 id="3422"><a href="lwg-defects.html#3422">3422</a>. Issues of <code>seed_seq</code>'s constructors</h3>
<p><b>Section:</b> 29.5.8.1 <a href="https://wg21.link/rand.util.seedseq">[rand.util.seedseq]</a> <b>Status:</b> <a href="lwg-active.html#C++23">C++23</a>
 <b>Submitter:</b> Jiang An <b>Opened:</b> 2020-03-25 <b>Last modified:</b> 2023-11-22</p>
<p><b>Priority: </b>3
</p>
<p><b>View all other</b> <a href="lwg-index.html#rand.util.seedseq">issues</a> in [rand.util.seedseq].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++23">C++23</a> status.</p>
<p><b>Discussion:</b></p>
<p>
29.5.8.1 <a href="https://wg21.link/rand.util.seedseq">[rand.util.seedseq]</a> says that <code>std::seed_seq</code> has following 3 constructors:
<p/>
<ol style="list-style-type: none">
<li><p>#1: <code>seed_seq()</code></p></li>
<li><p>#2: <code>template&lt;class T&gt; seed_seq(initializer_list&lt;T&gt; il)</code></p></li>
<li><p>#3: <code>template&lt;class InputIterator&gt; seed_seq(InputIterator begin, InputIterator end)</code></p></li>
</ol>
<p/>
The default constructor (#1) has no precondition and does not throw, and <code>vector&lt;result_type&gt;</code>'s default 
constructor is already <code>noexcept</code> since C++17, so #1 should also be <code>noexcept</code>.
<p/>
Despite that the <code>vector&lt;result_type&gt;</code> member is exposition-only, current implementations (at least 
<a href="https://github.com/llvm-mirror/libcxx/blob/master/include/random#L3523">libc++</a>, 
<a href="https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bits/random.h#L6090">libstdc++</a> and 
<a href="https://github.com/microsoft/STL/blob/master/stl/inc/random#L259">MSVC STL</a>) all hold it as the only 
data member of <code>seed_seq</code>, even with different names. And #1 is already <code>noexcept</code> in libc++ and libstdc++.
<p/>
These constructors are not constrained, so #3 would never be matched in list-initialization. Consider following code:
</p>
<blockquote><pre>
#include &lt;random&gt;
#include &lt;vector&gt;

int main()
{
  std::vector&lt;int&gt; v(32);
  std::seed_seq{std::begin(v), std::end(v)}; // error: #2 matched and T is not an integer type
  std::seed_seq(std::begin(v), std::end(v)); // OK
}
</pre></blockquote>
<p>
#3 should be made available in list-initialization by changing <i>Mandates</i> in 
29.5.8.1 <a href="https://wg21.link/rand.util.seedseq">[rand.util.seedseq]</a>/3 to <i>Constraints</i> IMO.
</p>

<p><i>[2020-04-18 Issue Prioritization]</i></p>

<p>Priority to 3 after reflector discussion.</p>

<p><i>[2021-06-23; Reflector poll]</i></p>

<p>
Set status to Tentatively Ready after five votes in favour during reflector poll.
</p>

<p><i>[2021-10-14 Approved at October 2021 virtual plenary. Status changed: Voting &rarr; WP.]</i></p>



<p id="res-3422"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/n4861">N4861</a>.
</p>

<ol>
<li><p>Modify 29.5.8.1 <a href="https://wg21.link/rand.util.seedseq">[rand.util.seedseq]</a> as indicated:</p>

<blockquote>
<pre>
class seed_seq {
public:
  <i>// types</i>
  using result_type = uint_least32_t;

  <i>// constructors</i>
  seed_seq() <ins>noexcept</ins>;
  [&hellip;]
};
</pre>
</blockquote>
<blockquote>
<pre>
seed_seq() <ins>noexcept</ins>;
</pre>
<blockquote>
<p>
-1- <i>Postconditions:</i> <code>v.empty()</code> is <code>true</code>.
<p/>
<del>-2- <i>Throws:</i> Nothing.</del>
</p>
</blockquote>
<pre>
template&lt;class T&gt;
  seed_seq(initializer_list&lt;T&gt; il);
</pre>
<blockquote>
<p>
-3- <i><ins>Constraints</ins><del>Mandates</del>:</i> <code>T</code> is an integer type.
<p/>
-4- <i>Effects:</i> Same as <code>seed_seq(il.begin(), il.end())</code>.
</p>
</blockquote>
</blockquote>
</li>
</ol>




</body>
</html>
