January 20, 2011 [phobos] array() function | ||||
---|---|---|---|---|
| ||||
I'm seeing a recently-added overload of array() that spells: ========== ElementType!(String)[] array(String)(String str); Convert a narrow string to an array type that fully supports random access. This is handled as a special case and always returns a dchar[], const(dchar)[], or immutable(dchar)[] depending on the constness of the input. ========== What are some good use cases for it? Andrei |
January 20, 2011 [phobos] array() function | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | I wrote this when I was cleaning up array(). The use case for it is that, in generic code, you generally assume that calling array() on a range will result in you receiving a random access range. This makes that assumption valid even for narrow strings. In other words, it eliminates an ugly special case.
On 1/20/2011 10:59 PM, Andrei Alexandrescu wrote:
> I'm seeing a recently-added overload of array() that spells:
>
> ==========
> ElementType!(String)[] array(String)(String str);
>
> Convert a narrow string to an array type that fully supports
> random access. This is handled as a special case and always returns a
> dchar[], const(dchar)[], or immutable(dchar)[] depending on the
> constness of the input.
> ==========
>
> What are some good use cases for it?
>
>
> Andrei
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
>
|
Copyright © 1999-2021 by the D Language Foundation