How to count equal, adjacent elements in a vector?
<p>Lets say I have a <code>vector&lt;int&gt; { 1, 1, 2, 3, 3, 3, 1, 1 }</code> and I'd like to convert this into a <code>vector&lt;std::pair&lt;int, int&gt;&gt; { {1, 2}, {2, 1}, {3, 3}, {1, 2} }</code> of 'adjacent element counts':</p>

<p>I'd probably iterate over the vector with a flag indicating the start of a new 'adjacency set' and a counter which counts the number of consecutive elements. I was just wondering if there isn't already a more abstract and elegant solution in the STL as this seems like a very common use-case. Algorithms like unique, adjacent_find or equal_range seem pretty close to what I'm looking for but just not quite the right thing and probably no gain to implementing it from scratch myself.</p>