RE: [boost] Re: static sized strings

John Nagle wrote:
Since space for a trailing null is required, the minimum "capacity" is currently 1.
The maximum value for "size()" is then "capacity()-1". That seems a little wierd. Should the trailing null be counted in "capacity?"
This is a good point. At the moment fixed_string< n >::capacity() == n. It would therefore make sense that this be changed so that either: [1] fixed_string< n >::capacity() == n - 1 -- this would seem counter-intuitive, as fixed_string< 1 > would not be able to store any characters! [2] change CharT str[ n ] to CharT str[ n + 1 ] -- i.e. add an extra character for the trailing null. This would make more sense, as it is similar to: char * str = new char[ s.length() + 1 ]; I personally but a vote for solution 2, but what do other people think? Regards, Reece _________________________________________________________________ It's fast, it's easy and it's free. Get MSN Messenger today! http://www.msn.co.uk/messenger

In article <BAY7-F100BnrqhugXhq0003f7da@hotmail.com>, "Reece Dunn" <msclrhd@hotmail.com> wrote:
John Nagle wrote:
Since space for a trailing null is required, the minimum "capacity" is currently 1.
The maximum value for "size()" is then "capacity()-1". That seems a little wierd. Should the trailing null be counted in "capacity?"
This is a good point. At the moment fixed_string< n >::capacity() == n. It would therefore make sense that this be changed so that either:
[1] fixed_string< n >::capacity() == n - 1 -- this would seem counter-intuitive, as fixed_string< 1 > would not be able to store any characters!
Same goes for char[1], if you assume the string is NUL-terminated.
[2] change CharT str[ n ] to CharT str[ n + 1 ] -- i.e. add an extra character for the trailing null. This would make more sense, as it is similar to: char * str = new char[ s.length() + 1 ];
I personally but a vote for solution 2, but what do other people think?
I vote for #1, because it makes the char[] -> fixed_string<n> transition easier. meeroh -- If this message helped you, consider buying an item from my wish list: <http://web.meeroh.org/wishlist>

I think the relationship between "size()" and "capacity()" has to be such that if "size() < capacity()" you can add a character. So "capacity()" should not include the trailing null. For consistency with "<string>", "size()" can't include the trailing null. The big question is whether the size specified in the declaration (as in "char_string<80>") includes the trailing null. I don't want to express an opinion on this until I've had some sleep. I can think of good arguments for both sides. John Nagle Reece Dunn wrote:
John Nagle wrote:
Since space for a trailing null is required, the minimum "capacity" is currently 1.
The maximum value for "size()" is then "capacity()-1". That seems a little wierd. Should the trailing null be counted in "capacity?"
This is a good point. At the moment fixed_string< n >::capacity() == n. It would therefore make sense that this be changed so that either:
[1] fixed_string< n >::capacity() == n - 1 -- this would seem counter-intuitive, as fixed_string< 1 > would not be able to store any characters!
[2] change CharT str[ n ] to CharT str[ n + 1 ] -- i.e. add an extra character for the trailing null. This would make more sense, as it is similar to: char * str = new char[ s.length() + 1 ];
I personally but a vote for solution 2, but what do other people think?
Regards, Reece
participants (3)
-
John Nagle
-
Miro Jurisic
-
Reece Dunn