Reverse string by separator Here is problem:
There is string (domain) divided by dots (like www.part1.partN.com)
Need to build reversed by dot string (like com.partN.part1.www)
Both strings are utf-8 encoded  

My solution:

std::string reverseHost(const std::string&amp; host)
{
    std::string ret;
    ret.reserve(host.size());

    size_t tail = host.size();
    size_t head = host.find_last_of('.');

    while (head != std::string::npos)
    {
        ret.append(host.c_str() + head + 1, tail - head - 1);
        ret += '.';

        tail = head;
        head = host.find_last_of('.', tail - 1);
    }

    ret.append(host.c_str(), tail);

    return ret;
}


Need to improve speed (or advice how to improve), raw memory and other tricks allowed. ty.
You've misspelt std::size_t.

Apart from that, the code seems reasonably straightforward if you always need to return a copy.

A two-pass algorithm (reverse the whole string, then reverse each of the individual components) might be faster, because you can operate in-place, without having to create a new string.  Of course, you'll only get the speed benefit if the caller doesn't need to retain the original (pass by value, and use std::move to control copying).