consecutive_find function for returning a consecutive range of elements
Your function does not work correctly. The bug is in the lines:

    marker = std::find_if_not(lead, last,
                              [&amp;lead] (value_type const&amp; x) { return x == *lead; });


Say you call the function with the following code:

std::vector&lt;int&gt; v{1, 2, 2, 2, 3};
auto it = consecutive_find(v.begin(), v.end(), 3);


In the function, you start with:

marker -&gt; 1
last   -&gt; 1


Then, in the first statement of the outer while block, you execute:

    lead = std::next(marker);


Now,

last   -&gt; 2


You break out of the first inner while block with count set to 1, Then you execute

    marker = std::find_if_not(lead, last,
                              [&amp;lead] (value_type const&amp; x) { return x == *lead; });


When this line is finished executing,

marker -&gt; 3


and you completely missed the correct return value.

You can change those lines to simply:

    marker = lead;


and the function works fine.

Here's a sample program and its output:

#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;

template &lt;class Iter&gt;
Iter consecutive_find(Iter first, Iter last, std::size_t n)
{
    Iter marker(first), lead(first);
    std::size_t count(1);

    while (lead != last)
    {
        lead = std::next(marker);
        while ((lead != last) &amp;&amp; (*marker == *lead)) { ++count; ++lead; }
        if (count == n)
        {
            if ((lead == last) || !(*lead == *marker))
                return marker;
        }
        marker = lead;
        count = 1;
    }
    return marker;
}

void test1()
{
   std::vector&lt;int&gt; v{1, 2, 2, 2, 3};
   auto it = consecutive_find(v.begin(), v.end(), 3);
   for (int i = 0; i &lt; 3 &amp;&amp; it != v.end(); ++i, ++it )
   {
      std::cout &lt;&lt; *it &lt;&lt; " ";
   }
   std::cout &lt;&lt; std::endl;
}

int main()
{
   test1();
}


Output:



2 2 2