
Beman Dawes wrote:
Why not just use Boost.Filesystem V3 for dealing with files and filenames? ... Your code can be written to be reasonably portable too, particularly if all you are concerned with is either Windows systems or POSIX-like systems that use utf-8 for filenames. If you want wider portability, you would have to avoid narrow strings so that on POSIX-like systems the wide strings could be converted to whatever narrow encoding the system uses.
No, if you want wider portability you want to avoid wide strings and use narrow strings (UTF-8 on Windows, no conversion on POSIX). You don't want to convert on POSIX because the narrow -> wide -> narrow conversion may not be exact. (*) On Windows, wide (UTF-16) -> narrow (UTF-8) -> wide (UTF-16) is exact. std::wstring is typically UTF-32 on POSIX, by the way, because wchar_t is 32 bits there - this is one additional source of non-portability if you go wide. (*) It will be exact if you use a single-byte encoding that maps every narrow character to a distinct Unicode code point, but then you can't use UTF-8 at the same time - you have to choose one or the other.