Plan for InputRange?

bauss jj_1337 at live.dk
Wed Sep 29 06:10:30 UTC 2021


On Wednesday, 29 September 2021 at 02:06:16 UTC, Paul Backus 
wrote:
> On Tuesday, 28 September 2021 at 15:07:59 UTC, Dukc wrote:
>> What should we do about this? One could argue that `moveFront` 
>> belongs to `InputAssignable` as opposed to `InputRange`, but I 
>> think it would be too much breakage to change it like that 
>> anymore.
>
> Maybe `moveFront` could throw an exception at runtime if the 
> wrapped range does not support it. Something like the following:
>
> ```d
> override E moveFront()
> {
>     static if (__traits(compiles, r.moveFront))
>         return r.moveFront;
>     else
>         throw new Exception("Cannot move the front of a `" ~ 
> typeof(r).stringof ~ "`");
> }
> ```
>
> It's a stupid hack, but that may be the best way to work around 
> a stupid design mistake like this.

Why should it throw an exception when you can detect it at 
compiletime?

```
override E moveFront()
{
     static if (__traits(compiles, r.moveFront))
         return r.moveFront;
     else
         static assert(0, "Cannot move the front of a `" ~ 
typeof(r).stringof ~ "`");
}
```


More information about the Digitalmars-d mailing list