title: STL - Copy mixing containers
body: <p>I am trying to understand STL algorithms. </p>
  
  <p>Copy is defined as : </p>
  
  <pre><code>template&lt;class InputIterator, class OutputIterator&gt;
    OutputIterator copy ( InputIterator first, InputIterator last, OutputIterator result )
  </code></pre>
  
  <p>Can some one please explain why does the following works when vectors &amp; deques are mixed but fails when vectors and sets are mixed.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;algorithm&gt;
  #include &lt;vector&gt;
  #include &lt;deque&gt;
  #include &lt;deque&gt;
  #include &lt;set&gt;
  using namespace std;
  
  int main () {
    int myints[]={10,20,30,40,50,60,70};
    vector&lt;int&gt; myvector;
    vector&lt;int&gt;::iterator it;
  
    set&lt;int&gt; mset(myints,myints+8);
    set&lt;int&gt;::iterator setItr = mset.begin();
  
  
  
  
    deque&lt;int&gt; deq;
    deq.resize(10);
    deque&lt;int&gt;::iterator deqItr = deq.begin();
    myvector.resize(7);   // allocate space for 7 elements
    copy ( myints, myints+7, myvector.begin() );
  
    copy ( myvector.begin(), myvector.end(), deqItr );
    cout &lt;&lt; "deque contains:";
    for (deque&lt;int&gt;::iterator dit=deq.begin(); dit!=deq.end(); ++dit)
      cout &lt;&lt; " " &lt;&lt; *dit;
  
    cout &lt;&lt; endl;
  
    //copy ( myvector.begin(), myvector.end(), setItr );
  
  
    return 0;
  }
  </code></pre>
  
  <p>I understand vectors/deque have random access iterators,  where as set's have bidirectional iterators. I fail to understand why compilation fails when only a input/output iterators are required. </p>
  
  <p>PS : This is just an experiment to increase my understanding :)</p>