Unable to use template functions to define variables of a class

Subhaditya Nath sn03.general at gmail.com
Sat Oct 28 12:38:42 UTC 2023


This works fine –
```d
import std.stdio : writeln;
import std.range : iota, take;
import std.algorithm : filter, map, each;

void main() {
         auto range1 = iota(0, 100)
                         .filter!(x => x % 2)
                         .take(50);
         range1.each!writeln;
}
```

This also works fine –
```d
void main() {
         auto cls = new Class;
         cls.range1.each!writeln;
}

class Class {
         auto range1 = iota(0, 100)
                         .take(50);
}
```

But this doesn't –

```d
void main() {
         auto cls = new Class;
         cls.range1.each!writeln;
}

class Class {
         auto range1 = iota(0, 100)
                         .filter!(x => x % 2)
                         .take(50);
}
```

Adding the `.filter!` messes things up.


Same with `.map!`
```d
void main() {
         auto cls = new Class;
         cls.range1.each!writeln;
}

class Class {
         auto range1 = iota(0, 100)
                         .map!(x => x * 2)
                         .take(50);
}
```

My question is, why?

I mean, am I just dumb or is this some kinda bug?


More information about the Digitalmars-d-learn mailing list