Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2005-05-13 08:05:52

Martin wrote:
>Wouldn't the flex_string be even more flexible if it accepted ranges in
>constructor, assignment etc.
>(same for fixed_string, const_string of course)

This is true. However, this may result in undesired behaviour. For example:

template< typename String >
void foo( String & str, const std::vector< typename String::char_type > &
vec )
   str.assign( vec ); // uses assign( const RangeT & range )

int main()
   flex_string< char, SomeStringType > str1;
   std::string str2;
   std::vector< char > vec; // = "Meine Welt!"

   foo( str1, vec ); // ok: str1 = "Meine Welt!"
   foo( str2, vec ); // error - std::string does not have assign( const
std::vector< char > & )!

This may change in either a TR or the next standard if/when ranges are added
and incorporated into std::basic_string.

>Then you could easily switch between different string types without the

This deepnds on whether begin(input), etc. would detect that flex_string has
begin()/end() defined. Of course, the logic could be added to the begin(
RangeT ) and end( RangeT ) definitions.

>template <class RangeT>
>flex_string(const RangeT& input, const A& a = A())
>: Storage(a)
> assign(begin(input), end(input));

Couldn't this be assign( input ), since assing would have a RangeT variant.


Reece Haston Dunn
Software Engineer, Sophos

Sophos - protecting businesses against viruses and spam

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