[phobos] isStringLike

Andrei Alexandrescu via phobos phobos at puremagic.com
Tue Oct 27 07:28:25 PDT 2015


That is sensible. However, another way to look at it is:

1. "alias this" implements subtyping

2. By using "alias this" with string, DirEntry is subtyping the string type

3. A subtype of a range should be a range

Therefore, DirEntry is a range so the language needs to figure how to 
treat it as such.

To some extent I'm playing devil's advocate because I foresee the 
difficulties in making this work.

Andrei

On 10/26/15 5:27 PM, Walter Bright via phobos wrote:
>
>
> On 10/26/2015 9:27 AM, Dmitry Olshansky via phobos wrote:
>> Agreed. That is my opinion as well, however luck of any attention from
>> you and Walter led to the point where we
>> need (a) and (b) to work right now and we hacked it (somewhat of
>> speaking for the community here, correct me if I'm wrong).
>
> My recommendation was to remove the alias this in DirEntry that tried to
> turn it into a string. A DirEntry is not a wrapper for a string, in
> particular, it does not support range primitives, which is why the
> string functions failed when changed to have InputRange parameters.
> Adding range primitives to DirEntry would cause other weird problems,
> because DirEntry is fundamentally not a range (a range 'consumes' its
> data via popFront() which makes no sense for DirEntry).
>
> Yes, that breaks:
>
>      DirEntry direntry;
>      remove(direntry);
>
> which must be rewritten as:
>
>      DirEntry direntry;
>      remove(direntry.name);
>
> and we're not supposed to break existing code. But the alternative,
> which is redoing every template that accepts an InputRange, seems an
> awfully heavy burden. Even if we do this change pervasively in Phobos,
> how does that help anyone else who uses InputRanges?
>
> Tl,dr: the alias this in DirEntry is an abusive bad practice, and should
> never have happened.
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos


More information about the phobos mailing list