using the example from cppreference:
std::codecvt - cppreference.com
I've managed to convert from utf-8 to utf-32. here is my code:
it works with this example, but I wanted to ask few questions:Code:template<class Facet> struct deletable_facet : Facet { template<class ...Args> deletable_facet(Args&& ...args) : Facet(std::forward<Args>(args)...) {} ~deletable_facet() {} }; int main(){ std::string data = "hello world"; std::wstring_convert<deletable_facet<std::codecvt<char32_t, char, std::mbstate_t>>, char32_t> toUTF32Convertor; std::u32string str32 = toUTF32Convertor.from_bytes(data); }
1) is this code valid? it works for "hello world" example, yes, but I wonder if it's a one-time charm or is it actually functioning like it should.
2) I don't get the whole "inherit from unknown Facet class and move all the arguments to the base constructor"
3) I don't get the whole "inherit from std::codecvt", why do we need to inherit from coedcvt at the first place?
(4- why couldn't we get some nicer API :-) ?)