Boost logo

Boost :

From: John Nagle (nagle_at_[hidden])
Date: 2004-05-27 01:27:06


Rob Stewart wrote:

> 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?

  That's actually useful. Consder the
>
>
>> 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.
>


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