Create ranges from an array of integers
You can make good use of std::adjacent_find. Like this:

std::string range_creator(std::vector&lt;int&gt; &amp; vec)
{
    auto first = std::begin(vec), last = std::end(vec);
    if(first == last)
        return "";
    std::sort(first, last);
    std::stringbuf buffer;
    std::ostream os (&amp;buffer);
    while(true)
    {
        auto mid = std::adjacent_find(first, last,
                [](int x, int y){ return x + 1 != y; });
        if(mid == last)
            break;
        if(first == mid)
            os &lt;&lt; *first &lt;&lt; ",";
        else
            os &lt;&lt; *first &lt;&lt; "-" &lt;&lt; *mid &lt;&lt; ",";
        first = ++mid;
    }
    if(first == --last)
        os &lt;&lt; *first;
    else
        os &lt;&lt; *first &lt;&lt; "-" &lt;&lt; *last;
    return buffer.str();
}


I think my code is still subject to further improvements, but I'm no expert, so I'll leave it to the community.