copy_if_max() algorithm
I think you're overcomplicating the solution a bit. Since you're making copies of what is the maximum in the range, all you need is something that keeps a value to store the current max, and another which keeps a count of the number of maximum values that have been found in the input data. For example:

#include &lt;iterator&gt;

template &lt;typename InputIter, typename OutputIter&gt;
void copy_if_max(InputIter begin, InputIter end, OutputIter out_begin)
{
    std::size_t count = 1;
    typedef typename std::iterator_traits&lt;InputIter&gt;::value_type T;

    if(begin == end) return;

    T current_max = *begin;
    ++begin;

    while(begin != end) {
        if(*begin &gt; current_max) {
            current_max = *begin;
            count = 1;
        } 
        else if(*begin == current_max) {
            ++count;
        }
        ++begin;
    }

    for(std::size_t i = 0; i &lt; count; ++i) {
        *out_begin++ = current_max;
    }
}


Note that this solution also uses std::iterator_traits&lt;T&gt;, which you should be using instead of relying on the InputIterator passed having a nested value_type typedef (which will of course be false if it is passed a T*, for example).