C++17 : codecvt deprecated. Panic?

P0618RO:  “…The entire header <codecvt> (which does not contain the class codecvt!) is deprecated, as are the utilities wstring_convert and wbuffer_convert. These features are hard to use correctly, and there are doubts whether they are even specified correctly. Users should use dedicated text-processing libraries instead…”

C++17 : codecvt deprecated. Panic?  Please don’t. My advice is to “stay cool calm and collected and all things will fall into place”. Read on.

In case you want to transform from any standard  string type to std::string type here is the solution:

Just one simple lambda.

In case you need to transform to another string type, I am sure you will be more than able to made it using the concept of the code above.

My preferred design would be:

No templates, just lambdas. Here is one almost comprehensive test:

That’s it. No codecvt in sight.

In case you have thoughts like: “How do I transform utf8 to utf16 ..”, well I dare to suggest: you think again.

ps: dbj::print() implementation is trivial for you, I am sure of it. Or just copy/paste my implementation.

 

Leave a Reply