Monday, April 14, 2008

static_string semantics redux

I'm currently using stlsoft::static_string to test the soon-to-be-released FastFormat library. (btw, if you're a user/reader of mine, you're probably heartily sick of the phrase "soon-to-be-released", I hear ya!)

static_string is a std::string-like string class that has a fixed internal buffer. It relies on contracts to force on the user respect for its limitations, to whit you may not attempt to cause the string contents to exceed the internal size.

That's all very well and good, as it's clear. What's probably not so cool is that people tend not to either grok, or want to respect, the principles of contract programming.

So it's occuring to me that static_string should evolve for STLSoft 1.10 and change its contracts from "you may not try to expand me beyond my capacity limit" to "if you try and expand me beyond my capacity limit" I will inform you (by an exception).

There's another evolution that would be good, and that's one that would be able to work atop an external character buffer. But that brings the notion of policy classes into play, and they suck in general.

So, I'm starting to think that we'll have either a separate class (template), or a base utility template that gets specialised in two different ways by, say, static_string and external_string class templates.

Watch this space ...

No comments: