|
Boost : |
From: Steven Watanabe (steven_at_[hidden])
Date: 2007-09-28 12:25:04
AMDG
Joseph Gauterin <joseph.gauterin <at> googlemail.com> writes:
>
> >> Variable-width-encoded strings should be fairly straightforward when they
> >> are immutable, but will probably get hairy when they can be modified.
> >True. I think the strings should be immutable. I think experience with
> >Java and C# compared to C++ shows that an immutable string class is
> >superior in most use cases
>
> I also agree that immutable strings are the way forward for VWEs.
>
> If we had mutable strings consider how badly the following would perform:
> std::replace(utfString.begin(),utfString.end(),SingleByteChar,MultiByteChar);
>
> Although this looks O(n) at first glance, it's actually O(n^2), as the
> container has to expand itself for every replacement. I don't think a
> library should make writing worst case scenario type code that easy.
I agree that mutable iterators are not a good idea, since they make
an operation that is normally O(1) linear. In addition, *iter = MultiByteChar
would invalidate all the other iterators to the string causing your
example to crash. However, I see no reason to prevent usage like
std::replace_copy(utfString.begin(),
utfString.end(),
std::back_inserter(newutfString),
SingleByteChar
MultibyteChar);
In Christ,
Steven Watanabe
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk