dmd 2.063 released with 260 bugfixes and enhancements

Mafi mafi at example.org
Thu May 30 11:39:47 PDT 2013


On Thursday, 30 May 2013 at 18:09:22 UTC, Jonathan M Davis wrote:
> On Thursday, May 30, 2013 20:00:24 Mafi wrote:
>> What a great release! Great work!
>> 
>> I really like the new langugage changes. One change caught my
>> attention: #10 "The Template This Parameter now changes the
>> member function qualifier". Does this mean that const/immutable
>> ranges can implement a useful opSlice? Like
>> 
>> struct MyRange!T {
>> T[] data;
>> 
>> MyRange!(ElementType!data) opSlice(this T)() {
>> return MyRange(data);
>> }
>> }
>> 
>> So that given the other range primitves this will work:
>> 
>> const myConstRange = MyRange([5, 6, 7, 8]);
>> foreach(x; myConstRange) {}
>> 
>> Could this be made work with 2.063?
>
> No, because you still have the fundamental problem that 
> MyRange!T and MyRange!
> (const T) are different types which potentially have no 
> relation to one another
> aside from the fact that they were generated by the same 
> template. In the
> general case, you can't just convert MyRange!T to 
> MyRange!(const T). It only
> works with arrays because the compiler understands them.
>
> - Jonathan M Davis

Well I'm aware of the fact that MyRange!T and MyRange!const(T) 
could be unrelated types. But they're not and the author the 
range provided a conversion function and called it opSlice(). 
Foreach shouldn't care if they're related or not, it should just 
call opSlice().


More information about the Digitalmars-d-announce mailing list