Disclaimer: I'm the author of the P0482 proposal that introduced char8_t
and deprecated u8path
.
Your observations are correct; it is not permissible to use reinterpret_cast
to produce a char8_t
pointer to a sequence of char
objects. This is discussed further at https://stackoverflow.com/a/57453713/11634221.
Though std::filesystem::u8path
has been deprecated in C++20, there are no plans for its imminent removal; you can continue to use it. Further, P1423 corrects an unintended consequence of the changes in P0482 and permits it to be called with ranges of both char
and char8_t
in C++20. As far as I'm aware, no implementors have annotated std::filesystem::u8path
as deprecated (I don't know if any plan to do so).
There is no (well-formed) way to produce a char8_t
pointer based view of a sequence of char
. It is possible to write a range/iterator adapter that, internally, converts the individual char
values to char8_t
on iterator dereference. Such an adapter could satisfy the requirements of the C++17 and C++20 random access iterator requirements for a non-mutable iterator (it can't satisfy requirements for a mutable iterator because the dereference operation wouldn't be able to provide an lvalue, nor could it satisfy requirements for a contiguous iterator). Such an adapter would suffice for calls to the std::filesystem::path
constructors that accept ranges. Hmm, this might be a useful enough adapter to add to https://github.com/tahonermann/char8_t-remediation.
An alternative to a view over the underlying char
data is, of course, to copy it, but I can appreciate why doing so might be considered undesirable (we already tend to do a lot of copying when working with std::filesystem::path
).