I've run into this situation a lot:
I have a function that returns a range (in this case, a slice of
a custom container).
In some cases, the function needs to return an empty range.
It sounded like takeNone was what I wanted:
@nogc auto fun() {
return (some_condition) ? getRange() : getRange.takeNone;
}
but there is a return type ambiguity. I finally ended up doing
this:
@nogc auto fun() {
return (some_condition) ? getRange().take(size_t.max) :
getRange.takeNone;
}
I'm not sure if this is clever or insane.
It works, but just looks a bit crazy to me.
Does anyone else run into this situation? Have any cool ways to
solve it?
MyRange is an inputRange, and I can't use a wrapper (InputRange)
and keep the @nogc.