Plan for InputRange?

Paul Backus snarwin at gmail.com
Wed Sep 29 14:49:33 UTC 2021


On Wednesday, 29 September 2021 at 08:20:31 UTC, Dukc wrote:
> Perhaps it could do a regular `assert(false)` though. I'm not 
> sure it should throw an exception, since calling `moveFront` 
> where one is not implemented is a bug, not an environmental 
> error. On the other hand catchable exceptions are the simplest 
> way to let the user to introspect whether the elements are 
> mobile.

When you use `assert`, you put the responsibility on the calling 
function to avoid the failure case (e.g., by calling `empty` 
before calling `front`). In this case, though, because 
`InputRange` hides the wrapped range's original type, there is 
nothing the caller can do in advance to check whether `moveFront` 
will fail. So it has to be `moveFront`'s responsibility to detect 
failure, which means it must use a recoverable exception.


More information about the Digitalmars-d mailing list