Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2004-06-12 16:20:20

John Nagle wrote:
> I think we're back to using an abstract base class.
>The hacks to get around it introduce worse problems.

I would agree. I have been trying to find a way around the problem and have
(sortof) by having a base class:

   template< typename CharT >
   class string_base
         size_t len, cap; // length & capacity
         CharT * buf; // data buffer
         string_base( CharT * b, size_t c, size_t l ):
            len( l ), cap( c ), buf( b ){}
         // non-virtual implementation

   template< size_t n, typename CharT >
   class fixed_string: public string_base
         CharT data[ n + 1 ];
         fixed_string(): string_base( data, n + 1 ){}

The problems with this revolve around swapping/construction/copying and
interfacing with (in my case) basic_string_impl. I cannot find a way around
these problems without sacrificing something.

> Take a look at my approach at
>That's a straightforward approach. The only
>fundamental objection is that you take a virtual function
>call overhead on some operations.

That's the same with both approaches. Both designs are fundamentally the
same and I don't see a way around this. It would be interesting to do a
comparison with the 3 approaches (raw strcpy, etc on a char[ n ] buffer;
your approach and mine) in virtual and non-virtual situations to compare

>What needs to be done to that?

Are you aiming at supporting basic_string operations? If so, the class needs
more work (all the find functions, for instance). If, however, you are just
going for C-string replacement it is fine. One point on naming: the
wide-character operations are wcscpy (strcpy), wcscat (strcat), wcscmp
(strcmp), wcslen (strlen) and [v]swprintf (sprintf).

>Should I check it into the Boost sandbox, and
>if so, how? Comments, please. Thanks.

Go for it! You need a sourceforge account with CVS write access to the
boost-sandbox. There is documentation at the sourceforge site for setting it
up and pointers to the various tools. You will need to contact an
administrator for write access once you have the sourceforge stuff setup.


Express yourself with cool new emoticons

Boost list run by bdawes at, gregod at, cpdaniel at, john at