title: STL fill and forward iterator
body: <p>According to most C++ references, for instance cplusplus.com, <a href="http://cplusplus.com/reference/iterator/ForwardIterator/" rel="nofollow">forward iterators</a> are not required to be assignable (I mean, deferenced to an lvalue). However, for several STL algorithms that need to write values, for instance <a href="http://cplusplus.com/reference/algorithm/fill/?kw=fill" rel="nofollow"><code>std::fill</code></a> (also <code>std::generate</code> etc.), the specification uses forward iterator:</p>
  
  <pre><code>template &lt;class ForwardIterator, class T&gt;
    void fill (ForwardIterator first, ForwardIterator last, const T&amp; val);
  </code></pre>
  
  <p>while the equivalent behavior requires lvalue dereference:</p>
  
  <pre><code>template &lt;class ForwardIterator, class T&gt;
    void fill (ForwardIterator first, ForwardIterator last, const T&amp; val)
  {
    while (first != last) {
      *first = val;
      ++first;
    }
  }
  </code></pre>
  
  <p>So, it is actually using a mutable forward iterator with a single pass.</p>
  
  <p>Now the questions are:</p>
  
  <p>(1) Why not make it clear that the forward iterators used in these cases are mutable?</p>
  
  <p>(2) <strong>Update</strong>: I found the following question to be stupid: I temporarily forgot that output iterators do not need to support equality comparison. The above question remains, anyway.</p>
  
  <p>Why use forward iterators instead of output iterators for <code>std::fill</code>, <code>std::generate</code> etc. while they do not actually need multiple passes? (<code>std::copy</code> only needs output iterators, for instance. What's the rationale?)</p>