On Sun, Feb 26, 2012 at 5:25 AM, Ali Çehreli <acehr...@yahoo.com> wrote: > On 02/25/2012 08:25 AM, Ashish Myles wrote: >> However the code above doesn't seem to work and requires me to >> explicitly invoke the slice operator myself like >> foreach(p; C[]) { ... } >> when my data structure clearly defines the following functions. >> Point3[] opSlice() { return _cpts[]; } >> const (Point3)[] opSlice() const { return _cpts[]; } >> Is this a misunderstanding on my part or an unimplemented feature? > > But I've just verified that the following works with dmd 2.058: > > import std.stdio; > > struct Point3 > {} > > struct MyCollection > { > Point3[] _cpts; > > Point3[] opSlice() { return _cpts; } // <-- _cpts[] works too > > const (Point3)[] opSlice() const { return _cpts; } > } > > void main() > { > auto coll = MyCollection(); > > foreach (i; coll) { > // ... > } > } >
Oh good to know. I had downgraded my dmd after some new CTFE bugs resulted in compilation errors on some of my code, and hadn't thought to check with the latest version.