Naming things in Phobos - std.algorithm and writefln

Michel Fortin michel.fortin at michelf.com
Wed Aug 5 17:35:16 PDT 2009


On 2009-08-05 19:16:17 -0400, Jarrett Billingsley 
<jarrett.billingsley at gmail.com> said:

> On Wed, Aug 5, 2009 at 7:00 PM, Michel Fortin<michel.fortin at michelf.com> wr
> ote:
>> 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 d
> one
>> 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.

Looks pretty much like this bug. Put your vote on it.
<http://d.puremagic.com/issues/show_bug.cgi?id=2814>

There's also such an example in the original enhancement proposal for 
alias this from Andrei.
<http://d.puremagic.com/issues/show_bug.cgi?id=2631>

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list