title: Find over an Unsorted vector<int>
body: <p>I need to apply a <em>FIND</em> functionality over vector elements (similar to the <em>MATLAB FIND</em> command) returning all ocurrences. While being unable to find this using the <em>STL</em> functions with iterators, i concocted this function:</p>
  
  <pre><code>vector&lt;int&gt; find(vector&lt;int&gt; v, int value,vector&lt;int&gt;*ive)
  {
      //Generic Find
      vector&lt;int&gt; ve;
      for (int i=0;i&lt;v.size();i++)
      {
          if (v[i]==value)
          {
              ive-&gt;push_back(i);
              ve.push_back(v[i]);
          }
      }
  return ve;
  }
  </code></pre>
  
  <p>called with:</p>
  
  <pre><code>//Values
  vector&lt;int&gt; v1 = {1,3,3,4,5,2,3,4,6,7,7,8,1,2,2,3,2,2,3,2};
  vector&lt;int&gt; iRange,vRange;
  int val=2;
  
  //Manual FIND
  vRange=find(v1,val,&amp;iRange);
  PrintArray(vRange);
  PrintArray(iRange);
  </code></pre>
  
  <p>Returning the correct result:</p>
  
  <pre><code>vRange: 2 2 2 2 2 2 
  iRange: 5 13 14 16 17 19
  </code></pre>
  
  <p>Which of course do not use the <em>pair</em> object, the <em>sort()</em> and *equal_range()* function, which would be the ideal:</p>
  
  <pre><code>pair&lt;vector&lt;int&gt;::iterator,vector&lt;int&gt;::iterator&gt; Range;
  sort(v1.begin(),v1.end());
  Range=equal_range(v1.begin(),v1.end(),val);
  </code></pre>
  
  <p>Returning the <em>absolutely proper</em>, but so far <strong>totally useless</strong> result, if one wishes the result over the original, unsorted vector:</p>
  
  <pre><code>Range Iters: 2 2 2 2 2 2 
  Range:       2 3 4 5 6 7
  </code></pre>
  
  <p>How should i use STL for this?</p>
  
  <p>Thanks,
  hyp</p>