Appending a codepoint to an UTF8 std::string using icu4c
Beauty is in the eye of the beholder. I say it is perfectly valid and correct code! The only thing you might get rid of is the static_cast&lt;uint32_t&gt;, as an UChar32, which is an alias forint32_t, will implicitly cast to uint32_t without warnings.
You could also use append() instead of resize(), avoiding the addition, and remove the temporary ptr, to finally get:
void utf8_append(UChar32 cp, std::string&amp; str) {
    auto offset = str.size();
    str.append(U8_LENGTH(cp), {});
    U8_APPEND_UNSAFE(reinterpret_cast&lt;uint8_t *&gt;(&amp;str[0]), offset, cp);
}

If you can use C++17, str.data() is slightly nicer than &amp;str[0] in my opinion. Or you could write &amp;str.front().