<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 737: Comment on [rand.dist.samp.pconst]</title>
<meta property="og:title" content="Issue 737: Comment on [rand.dist.samp.pconst]">
<meta property="og:description" content="C++ library issue. Status: NAD">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue737.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="737"><a href="lwg-closed.html#737">737</a>. Comment on [rand.dist.samp.pconst]</h3>
<p><b>Section:</b> 29.5.9.6.2 <a href="https://wg21.link/rand.dist.samp.pconst">[rand.dist.samp.pconst]</a> <b>Status:</b> <a href="lwg-active.html#NAD">NAD</a>
 <b>Submitter:</b> Stephan Tolksdorf <b>Opened:</b> 2007-09-21 <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.dist.samp.pconst">issues</a> in [rand.dist.samp.pconst].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#NAD">NAD</a> status.</p>
<p><b>Discussion:</b></p>
<ol style="list-style-type:lower-alpha">
<li>
The discussion in point T11 above regarding <code>probabilities()</code> similarly applies 
to the method <code>densities()</code> of <code>piecewise_constant_distribution</code>.
</li>
<li>
<p>
The design of the constructor
</p>
<blockquote><pre>
template &lt;class InputIteratorB, class InputIteratorW&gt; 
piecewise_constant_distribution( InputIteratorB firstB, InputIteratorB lastB, 
                                 InputIteratorW firstW);
</pre></blockquote>
<p>
is unnecessarily unsafe, as there is no separate end-iterator given for the weights. I can't see 
any performance or convenience reasons that would justify the risks inherent in such a function 
interface, in particular the risk that input error might go unnoticed.
</p>
</li>
</ol>

<p>
<b>Possible resolution:</b> I propose to add an <code>InputIteratorW lastW</code> argument to the interface.
</p>

<p><i>[
Stephan Tolksdorf adds pre-Bellevue:
]</i></p>

<blockquote><p>
In reply to the discussion in
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2424.pdf">N2424</a>
I'd like to make the same comments as for <a href="lwg-closed.html#736" title="Comment on [rand.dist.samp.discrete] (Status: NAD)">736</a><sup><a href="https://cplusplus.github.io/LWG/issue736" title="Latest snapshot">(i)</a></sup>.
</p></blockquote>

<p><i>[
Bellevue:
]</i></p>


<blockquote><p>
In N2424. There is already precedent elsewhere in the library. Follows existing convention. NAD.
</p></blockquote>


<p id="res-737"><b>Proposed resolution:</b></p>
<p>
See <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2424.pdf">N2424</a>
for the proposed resolution.
</p>

<p><i>[
Stephan Tolksdorf adds pre-Bellevue:
]</i></p>


<blockquote>
<p>
In 29.5.9.6.2 <a href="https://wg21.link/rand.dist.samp.pconst">[rand.dist.samp.pconst]</a>:
</p>

<p>
Proposed wording a)
</p>

<blockquote>
<p>
Change in para. 2
</p>
<blockquote><p>
Constructs a <code>piecewise_constant_distribution</code> object with <code>n = 1</code>, <code>p<sub>0</sub> <ins>= w<sub>0</sub></ins> = 1</code>,
<code>b<sub>0</sub> = 0</code>, and <code>b<sub>1</sub> = 1</code>
</p></blockquote>

<p>
and change in para. 5
</p>

<blockquote><p>
A <code>vector&lt;result_type&gt;</code> whose <code>size</code> member returns <code>n</code> and whose <code>operator[]</code>
member returns <del><code>p<sub>k</sub></code></del>
<ins>the weight <code>w<sub>k</sub></code> as a double value</ins>
when invoked with argument <code>k</code> for <code>k = 0, ..., n-1</code>
</p></blockquote>

</blockquote>

<p>
Proposed wording b)
</p>

<blockquote>
<p>
Change both occurrences of
</p>

<blockquote><pre>
"piecewise_constant_distribution(InputIteratorB firstB, InputIteratorB lastB,
                                 InputIteratorW firstW<ins>, InputIteratorW lastW</ins>)
</pre></blockquote>

<p>
and change in para. 3
</p>

<blockquote><p>
<del>the length of the sequence <code>w</code> starting from <code>firstW</code> shall be at least <code>n</code>,
<code>*firstW</code> shall return a value <code>w<sub>0</sub></code> that is convertible to <code>double</code>, and any
<code>w<sub>k</sub></code> for <code>k &gt;= n</code> shall be ignored by the distribution</del>
<ins><code>[firstW, lastW)</code> shall form a sequence <code>w</code> of length <code>n</code> whose leading element
<code>w<sub>0</sub></code> shall be convertible to <code>double</code></ins>
</p></blockquote>

</blockquote>


</blockquote>






</body>
</html>
