Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2004-05-25 17:19:48


Rob Stewart wrote:
>From: "Reece Dunn" <msclrhd_at_[hidden]>
> > To simplify my design, I could implement basic_string_impl using the
>policy
> > approach that flex_string uses.

>Sorry, I don't know anything about flex_string, but what you've
>shown would only serve to make your string class more painful
>than John's (or your) current approach.

I have come up with the following design that should satisfy all
requirements:

[1] it retains the basic_string interface in fixed_string_base (and thus
[w]char_string) and fixed_string< n >

[2] it retains the existing usage

[3] it allows the use of char_string for operating on fixed_string< n, char
> for any n without resorting to templates

[4] it hides the implementation functions from the main interface and should
now allow aggressive inlining of the code

   namespace detail
   {
      template< typename CharT, class Policy = std::char_traits< CharT > >
      struct fixed_string_iface{ /* ... */ };

      template< class Base >
      class basic_string_impl: private Base
      {
         public:
            typedef typename Base::char_type char_type;
            typedef typename Base::traits_type traits_type;
            // ...
      };
   }

   template< typename CharT, class Policy = std::char_traits< CharT > >
   struct fixed_string_base: public detail::basic_string_impl<
detail::fixed_string_iface< CharT, Policy > >
   {
      // ...
   };

   typedef fixed_string_base< char > char_string;
   typedef fixed_string_base< wchar_t > wchar_string;

   template< size_t n, typename CharT = char, class Policy =
std::char_traits< CharT > >
   class flex_string: public fixed_string_base< CharT, Policy >
   {
      // ...
   };

However, the implementation has another an additional class, making it
slightly more confusing to see what is happening; it does simplify
basic_string_impl, though!

NOTE: I have not fleshed out the above design, so don't know if it is truely
implementable (it seems so). I shall update the sandbox code to reflect the
above design when it is implemented.

Regards,
Reece

_________________________________________________________________
Want to block unwanted pop-ups? Download the free MSN Toolbar now!
http://toolbar.msn.co.uk/


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