title: C++ Vector Range Constructor
body: <p>I was looking over some C++ documentation when it occurred to me that the vector container doesn't have a constructor that 'easily' allows the user to pass a range of values - a min and a max - and have a vector constructed which has elements from min -> max. I thought this was odd so I tried writing my own and discovered it was non-trivial. Here's my solution.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;iterator&gt;
  #include &lt;algorithm&gt;
  
  template &lt;typename T&gt;
  class MyIterator: public std::iterator&lt;std::input_iterator_tag, int&gt;
  {
  
  public:
  
    MyIterator(T val):value(val) {}
    MyIterator(const MyIterator &amp; m):value(m.value) {}
  
    MyIterator&amp; operator ++() 
    {
    ++value; 
      return *this; 
    }
  
    MyIterator operator ++(int) 
    { 
      MyIterator temp(*this); 
      operator ++();
      return temp; 
    }
  
    bool operator ==(const MyIterator &amp; m) const { return value == m.value; }
    bool operator !=(const MyIterator &amp; m) const { return !(value == m.value); }
    T&amp; operator *() { return value; }
  
  private:
  
    T value;
  
  };
  
  int main(int argc, char** argv)
  { 
    std::vector&lt;int&gt; my_vec(MyIterator&lt;int&gt;(100), MyIterator&lt;int&gt;(400));
  
    std::copy(my_vec.begin(), my_vec.end(), std::ostream_iterator&lt;int&gt;(std::cout, "\n"));
  
    return 0;
  }
  </code></pre>
  
  <p>Does the new C++ have a solution for this?</p>