title: Unexpected behaviour of std::discrete_distribution
body: <p>I am using Visual Studio 2013 (debug mode), which doesn't have an iterator-based constructor for <code>std::discrete_distribution</code>, so I am using a workaround. However, when using this workaround, it produces a runtime error if the last element is not greater than the first element in <code>weights</code>.</p>
  
  <p>This error is not produced when using an initialisation list.</p>
  
  <p>Example:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;random&gt;
  #include &lt;vector&gt;
  
  int main(){
      std::discrete_distribution&lt;&gt; dist1 = { 10.f,11.f,5.f };
  
      std::cout &lt;&lt; "!" &lt;&lt; std::endl;
  
      std::vector&lt;float&gt; weights = { 10.f, 11.f, 5.f};
  
      std::size_t i(0);
  
      std::discrete_distribution&lt;&gt; dist2(weights.size(), weights.front(), weights.back(),
          [&amp;weights, &amp;i](double){
          auto w = weights[i];
          ++i;
          return w;
      });
  
      std::cout &lt;&lt; "!!" &lt;&lt; std::endl;
  
      return 0;
  }
  </code></pre>
  
  <blockquote>
    <p>Output:</p>
    
    <p>!</p>
    
    <p>invalid range for discrete_distribution</p>
  </blockquote>
  
  <p>Adding any number greater than 10 onto the end of <code>weights</code> would stop the runtime error occurring.</p>
  
  <p>Why is this happening?</p>