I have a library that produces std::vector<uint8_t>
's, I have an API which consumes std::vector<char>
's. I find myself in need of getting from point A to point B.
The line I'm using to do this right now is considered "bad" by most.
std::vector<std::uint8_t> in {...};
std::vector<char> out;
out = reinterpret_cast<std::vector<char>&&>(in);
But it produces reasonable code, and as a practical matter works everywhere despite being a straightforward violation of strict aliasing. I'm wondering if anyone has a clean way of doing this that doesn't anger the language lawyers and will keep me in the good graces of the compiler gods.
I know this code is bad, please do not tell me this code is bad/UB/call me a felon. I'm admitting to that up front. I'm also uninterested in the obviously correct answers that involve copying the vector, clearly trying to avoid the copy here.