ZY Zhou wrote:
Andrei Alexandrescu Wrote:
What can be done about that? I see a number of solutions:
(a) Do not operate the change at all.
(b) Operate the change and mention that in range algorithms you should
check hasLength and only then use "length" under the assumption that it
really means "elements count".
(c) Deprecate the name .length for UTF-8 and UTF-16 strings, and define
a different name for that. Any other name (codeUnits, codes etc.) would
do. The entire point is to not make algorithms believe strings have a
.length property.
(d) Have std.range define a distinct property called e.g. "count" and
then specialize it appropriately. Then change all references to .length
in std.algorithm and elsewhere to .count.
What would you do? Any ideas are welcome.
Andrei
I choose (b)
Perfect. Then you'll be glad to know that I changed all of Phobos to
support it. All unittests pass now, but I suspect there are a couple of
bugs left.
The change will be part of the next release. I'll commit during the
weekend. This is a very exciting development, I was very unhappy about
the interaction between std.algorithm and strings.
Andrei