|
Boost : |
From: Rob Stewart (stewart_at_[hidden])
Date: 2004-05-26 15:08:37
From: John Nagle <nagle_at_[hidden]>
>
> Since space for a trailing null is required, the
> minimum "capacity" is currently 1.
This means your class supports strings that can never contain any
data. Is that something that should be permissible?
> The maximum value for "size()" is then "capacity()-1".
> That seems a little wierd. Should the trailing null be
> counted in "capacity?"
No, capacity() should return the maximum value size() can attain.
Think about the typical approach to allocating a C string:
size_t const MAX_LENGTH(10);
char buffer[MAX_LENGTH + 1];
This permits using MAX_LENGTH in comparisons with
strlen(buffer). I think capacity() is analogous to MAX_LENGTH.
-- 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