Naming things in Phobos - std.algorithm and writefln

Jarrett Billingsley jarrett.billingsley at gmail.com
Wed Aug 5 16:16:17 PDT 2009


On Wed, Aug 5, 2009 at 7:00 PM, Michel Fortin<michel.fortin at michelf.com> wrote:
> Also, with implicit casts we wouldn't even need to bother about having a
> different names for lazy and non-lazy results, we could just do:
>
>        string[] parts = str.split();
>
> and it would implicitly convert the lazy range to an array. Can this be done
> with alias this? Would need to test.
>
>        struct Range(T)
>        {
>                T[] toArray();
>                alias toArray this;
>
>                ... other range things here...
>        }

Sadly it doesn't work.  I was hopeful when I found this works:

struct X { int x; alias x this; }
auto x = X(5);
int y = x; // works!

but if you alias a method that returns int to 'this', that line fails.



More information about the Digitalmars-d mailing list