[cppx] ZStr, an ownerhip transferring string type

The ZStr ownerhip transferring string class that I introduced in my first Xerces posting may have seemed like total overkill for the job. In C++98 it’s difficult to do correctly, and it requires some less-than-commonly available support machinery. And so if Xerces string handling was the only reason to do it, I wouldn’t have done it.

But once a string class like ZStr is available you (or at least I) find that it’s a natural first choice for many tasks. The beauty of it is that it allows you to defer the decision of trading efficiency for functionality, because the ownership can be transferred to an immutable sharing string type at any point. Or the string can be copied to a copying mutable string type like std::string, whatever.

With a type like ZStr, if you’re implementing library-like functionality, the decision of which “rich” string type does not have to be imposed on the client code. Instead of already trading away the efficiency you’re giving the client code the choice, including the choice of just using ZStr.

[… More] Read all of this posting →

Advertisement

Do it this way? Or that way? What’s best?

Long, heated debates, and long, painful agonizing over the choice, often result from “this, or that?”. E.g., return by value or take an in/out argument? The practical answer is often just “yes, both, thank you”, like Winnie the Pooh, and in some cases the practical answer is “a different way”, but for some mysterious reason the practical answer can be very hard to see.

[… More] Read all of this posting →