We are representing paths as boost::filesystem::path, but in some cases other APIs are expecting them as const char * (e.g., to open a DB file with SQLite).
From the documentation, path::value_type is a wchar_t under Windows. As far as I know, Windows wchar_t are 2 bytes, UTF-16 encoded.
There is a string() native observer that returns a std::string, while stating:
If string_type is a different type than String, conversion is performed by cvt.
cvt is initialized to a default constructed codecvt. What is the behaviour of this default constructed codecvt?
There is this forum entry, that recommends to use an instance of utf8_codecvt_facet as the cvt value to portably convert to UTF-8. But it seems that this codecvt is actually to convert between UTF-8 and UCS-4, not UTF-16.
What would be the best way (and if possible portable) to obtain an std::string representation of a path, making sure to convert from the right wchar_t encoding when necessary?