Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2004-06-01 16:02:55


From: John Nagle <nagle_at_[hidden]>
>
> I've done some cleanup on my version of fixed_string at
>
> http://www.animats.com/source
>
> This now conforms to Dunn's decision on length, i.e.
>
> "fixed_string<char,4> s" now has space for four characters
> plus a trailing null.

Good.

> I decided that "operator[]" had to let users reach the
> trailing null without a subscript error, so that the classic
> C idiom of a loop stopped by the trailing null
>
> for (i=0; s[i]; i++)

Good idea.

> would still work. Because "operator[]" can't tell a read from
> a write, this offers the possibility of overstoring the

Sure it can: just return a proxy. Assignment through the proxy
is a write and can be checked against exceeding N. Conversion of
the proxy to the character type is a read and can permit
accessing element N + 1.

> trailing null. But c_str() will always reset the trailing
> null if necessary.

Will you still need to reset the trailing null if using the
proxy?

> The functions of fixed_string are now all accessable
> via fixed_string_base, as virtual functions, which was
> an ommission in the previous version.

Good.

-- 
Rob Stewart                           stewart_at_[hidden]
Software Engineer                     http://www.sig.com
Susquehanna International Group, LLP  using std::disclaimer;

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk