How to ensure an STL algorithm only iterates through a certain number of elements in a container?
<p>I need to return the bottom 10 elements in a map using a for_each algorithm. For some reason map iterators do not have random access so I cannot use:</p>

<pre><code>std::for_each(std::map.end(), std::map.end()-10, &lt;lambda&gt;);
</code></pre>

<p>I can use the -- operator on the iterators, but I'd rather not use ten of those!</p>

<p>So can someone let me know if there is a way to specify that the algorithm should only consider 10 of the elements?</p>
