Bug 13571 – Overload of std.range.tee which accepts a functions does not accept structs or classes with opCall

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-10-04T05:59:00Z
Last change time
2014-10-17T03:08:02Z
Assigned to
nobody
Creator
monkeyworks12

Comments

Comment #0 by monkeyworks12 — 2014-10-04T05:59:11Z
The following code does not work currently with tee: struct Callable { void opCall(int n) { writeln(n); } } void main() { auto ints = [1, 2, 3]; //Error auto res = ints.tee!Callable; } Note that the following code *does* work: struct Callable { void opCall(int n) { writeln(n); } } void main() { Callable callable; auto ints = [1, 2, 3]; auto r = ints.tee(callable); foreach (_; r) {} //Prints 1 2 3 } So I don't know how useful adding support for doing `tee!Callable` would be.
Comment #1 by monkeyworks12 — 2014-10-05T12:43:51Z
I tried adding support for opCall to tee, and I ran into some problems. As you can just pass the struct/object with opCall to the overload of tee that takes an output range as a function argument, the extra complexity that's necessary to support taking structs/objects with opCall as a template argument is not worth it IMO. Therefore, I'm going to close this.
Comment #2 by dlang-bugzilla — 2014-10-17T03:08:02Z
Probably the simplest way to implement this would be to make `tee` use `unaryFun`, and, if necessary, add `opCall` support to `unaryFun` instead.