www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Is it valid in D to write an opSlice overload that takes no arguments?

reply solidstate1991 <laszloszeremi outlook.com> writes:
Here's this code:

```d
auto opSlice()
{
     struct Range
     {
         Attr currentAttr;

         auto front() { return currentAttr; }
         void popFront() { currentAttr = currentAttr._nextAttr; }
         bool empty() { return currentAttr is null; }
     }
     return Range(firstAttr);
}
```

This was originally in std.experimental.xml in `domimpl.d`, and 
it causes LDC to segfault, but compiles fine under DMD.
Sep 11 2022
parent Adam D Ruppe <destructionator gmail.com> writes:
On Sunday, 11 September 2022 at 09:47:34 UTC, solidstate1991 
wrote:
 Here's this code:
This should be allowed, but also the way you're supposed to write it now is a no-argument opIndex.
Sep 11 2022