dmd 2.063 released with 260 bugfixes and enhancements

Jonathan M Davis jmdavisProg at gmx.com
Thu May 30 12:25:17 PDT 2013


On Thursday, May 30, 2013 20:39:47 Mafi wrote:
> 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().

You still need a way to convert MyRange!T to MyRange!(const T). opSlice won't 
do that magically for you. It'll just have to do that internally. And to be 
truly useful, you need to be able to go from const(MyRange!T) to
MyRange!(const T). You need tail-const:

http://d.puremagic.com/issues/show_bug.cgi?id=5377

I don't see how this enhancement could possibly have any effect on any of that. 
At best, it eliminates some code duplication.

- Jonathan M Davis


More information about the Digitalmars-d-announce mailing list