RE: [boost] Re: static sized strings

John Nagle wrote:
Reece Dunn wrote:
John Nagle wrote: The problems arise in the interation with basic_string_impl and how to implement swap and functions that require constructing a string object. Why do you need to construct a string object to swap? Just swap one character at a time.
There were 3 things I was cxonsidering when moving to the non-virtual implementation: [1] How do I pass the buffer and capacity to the implementation while allowing both fixed_string_base and fixed_string access to the basic_string interface? I have chosen to route the data through one of the basic_string constructors, requiring a const_cast. This is the best approach AFAICS. [2] How do I implement the swap function? The solution I arrived at is the one you suggest: to swap the data character-by-character. What you have to consider when doing this is that the strings don't exceed capacity, resulting in additional logic. [3] How do I approach the substr function and the + operators? Although it is now possible to construct a fixed_string_base object from a fixed_string object, you will run into problems when constructing from a temporary (because the fixed_string temporary will have been destroyed, invalidating the buffer). Given this, the implementation of these functions are still in fixed_string and thus not accessible to [w]char_string. I have replaced the old implementation with this one in the sandbox if you want to take a look. Also, feel free to adapt it to your version if you want. Regards, Reece _________________________________________________________________ It's fast, it's easy and it's free. Get MSN Messenger today! http://www.msn.co.uk/messenger

From: "Reece Dunn" <msclrhd@hotmail.com>
John Nagle wrote:
Reece Dunn wrote:
John Nagle wrote: The problems arise in the interation with basic_string_impl and how to implement swap and functions that require constructing a string object. Why do you need to construct a string object to swap? Just swap one character at a time.
[2] How do I implement the swap function? The solution I arrived at is the one you suggest: to swap the data character-by-character. What you have to
Unfortunately, that makes swap() O(N), but it does allow it to be nothrow.
consider when doing this is that the strings don't exceed capacity, resulting in additional logic.
That should fail, shouldn't it? Yes, that would mean a swap() that throws, but the strings aren't really swapped if you only swap some characters. I'm not sure which is worse: a swap() that throws or only partially swapping. The former violates exception safety guarantee assumptions made by other code, but the latter means that swap() may not really swap, which violates semantics. -- Rob Stewart stewart@sig.com Software Engineer http://www.sig.com Susquehanna International Group, LLP using std::disclaimer;

From: "Reece Dunn" <msclrhd@hotmail.com>
[1] How do I pass the buffer and capacity to the implementation while allowing both fixed_string_base and fixed_string access to the basic_string interface? I have chosen to route the data through one of the basic_string constructors, requiring a const_cast. This is the best approach AFAICS.
I haven't looked at your recent implementation, and I don't presently have the time, so I really don't know what you're talking about. If you can explain the dependencies to which you refer, I'd appreciate it. I think it has bearing on the swap() discussion. -- Rob Stewart stewart@sig.com Software Engineer http://www.sig.com Susquehanna International Group, LLP using std::disclaimer;
participants (2)
-
Reece Dunn
-
Rob Stewart