C++ get indexes of repeated value in std vector
<p>I want to get the indexes of a repeated value in a std::vector. What I'm doing is basically collect the indexes returned by std::find in a new vector, something like this:</p>

<pre><code>  auto beg = v.begin();
  const auto end = v.end();
  std::vector&lt;size_t&gt; val_positions;
  while (beg != end){
    auto iter = std::find(beg, end, val);
    if (iter != end){
      val_positions.push_back(iter - v.begin());
      beg = iter;
    }
    ++beg;
  }
</code></pre>

<p>This should cross the vector in linear time. Is there a more efficient way to do this? The vector is not sorted.</p>