I have an object of type std::wstring and a library function which takes const uint32_t* as an argument. My code is running on platforms where sizeof(wchar_t) == 4. There is no API in the library (harfbuzz) which takes const wchar_t*, so I must convert my std::wstring. I know that reinterpret_cast is not safe (it violates strict aliasing rule), but I don't want to create std::vector<uint32_t>, resize it and memcpy my whole string. I'm 100% sure that compiler will not optimize it out. And it seems that std::bit_cast can't help me too, it can convert only a single wchar_t to uint32_t.
I see only one solution: use reinterpret_cast. String will not be changed nor in my code neither in library so I don't think that violating strict aliasing rule is a problem in such a case.
Is there any other option? What do you do when type of data in your code doesn't match with input type in some C-library (int32_t* vs uint32_t*, char16_t* vs unsigned short*, etc.)?