I'm building a cross platform application, and I have a function which converts the platform character type into UTF-8.
#if _WIN32
typedef wchar_t platChar;
#else
typedef char platChar;
#endif
std::string ensureUtf8(platChar* chars);
Then, for the implementation on windows I would allocate a new string, call
WideCharToMultibyte
However, for the implementation on macos, I would just like to return the original string. If I do this:
std::string ensureUtf8(platChar* chars)
{
return std::string(chars);
}
However, the issue is, when I call std::string
constructor on chars
, it must copy chars. How can I avoid this?