Deciding one member of iteration chain at runtime
Chris Piker
chris at hoopjump.com
Fri Feb 17 17:30:40 UTC 2023
Hi D
I have a main "loop" for a data processing program that looks
much as follows:
```d
sourceRange
.operatorA
.operatorB
.operatorC
.operatorD
.operatorE
.operatorF
.operatorG
.operatorH
.copy(destination);
```
Where all `operator` items above are InputRange structs that take
an upstream range, and the pipeline really is 9 operations deep.
In order to handle new functionality it turns out that operatorG
needs to be of one of two different types at runtime. How would
I do something like the following:
```d
auto virtualG; // <-- probably invalid code, illustrating the
idea
if(runtime_condition)
virtualG = operatorG1;
else
virtualG = operatorG2;
sourceRange
.operatorA
.operatorB
.operatorC
.operatorD
.operatorE
.operatorF
.virtualG
.operatorH
.copy(destination);
```
?
I've tried various usages of `range.InputRangeObject` but haven't
been able to get the syntax right. Any suggestions on the best
way to proceed? Maybe the whole chain should be wrapped in
InputRangeObject classes, I don't know.
Thanks,
More information about the Digitalmars-d-learn
mailing list