`idup` is only available for built-in arrays, and `Range` may be any range type. I think you can just use `return distance(t, s);` to do the swap (would be worth factoring out the length calculations though).