An implementation of maximum subarray finding algorithm in STL style I am reading Stroustrup now and I was very impressed with how flexible the STL library is thanks to iterators and generic programming. Along the way, I am also reading Cormen's book and decided to try to implement an algorithm for searching for the maximum subarray in the style of STL. I wrote in C++11. I would be very grateful to hear your opinion about this code.

template&lt;typename For&gt;
// Requires Forward_iterator&lt;For&gt;()
auto find_maximum_subarray (For begin, For end)
{
    typename std::iterator_traits&lt;For&gt;::value_type max_sum_subarr = *begin;
    typename std::iterator_traits&lt;For&gt;::value_type max_sum        = *begin;

    For subarr_begin = begin;
    For left = begin;
    For right = ++begin;

    for (; begin != end; ++begin)
    {
        if (max_sum_subarr &gt; 0)
            max_sum_subarr += *begin;
        else
        {
            max_sum_subarr = *begin;
            subarr_begin = begin;
        }

        if (max_sum_subarr &gt; max_sum)
        {
            left = subarr_begin;
            right = begin;
            ++right;
            max_sum = max_sum_subarr;
        }
    }
    return make_tuple (left, right, max_sum);
}
Do not rely on the client code to #include necessary headers. The client has no idea which headers your file requires. Spell them out explicity:

#include &lt;iterator&gt;
#include &lt;tuple&gt;

Are you sure you are using c++11? I am getting

error: 'auto' return without trailing return type; deduced return types
are a C++14 extension

In general, naked auto returns in an interface is a dubious idea. Again, think of the client. The client should not analyze your template to deduce what it actually returns. It is OK to have them in the helper functions not exposed to the client.
It took me a while to figure out why your code works correctly. The side effect of ++ in

For right = ++begin;


is very easy to miss.