Relaxing the definition of isSomeString and isNarrowString
via Digitalmars-d
digitalmars-d at puremagic.com
Sun Aug 24 06:00:38 PDT 2014
On Sunday, 24 August 2014 at 01:06:31 UTC, Andrei Alexandrescu
wrote:
> Currently char[], wchar[], dchar[] and qualified variants
> fulfill the requirements of isSomeString. Also, char[], wchar[]
> and qualified variants fulfill the requirements of
> isNarrowString.
>
> Various algorithms in Phobos test for these traits to optimize
> away UTF decoding where unnecessary.
>
> I'm thinking of relaxing the definitions to all types that
> fulfill the following requirements:
>
> * are random access ranges
> * element type is some character
> * offer .ptr as a @system property that offers a pointer to the
> first character
>
> This would allow us to generalize the notion of string and
> offer optimizations for user-defined, not only built-in,
> strings. Thoughts?
IMO in general it's a good proposal; I expected `isSomeString` to
return `true` for higher-order ranges over strings, and was
surprised that it didn't.
But `.ptr` must only be included if the elements are indeed
contiguous in memory. For example, `std.algorithm.filter` applied
to a string should not provide `.ptr`, but should IMO be treated
as a string nevertheless.
Related: What about `.length`? RA ranges can also be infinite...
More information about the Digitalmars-d
mailing list