Plan for InputRange?
Dukc
ajieskola at gmail.com
Wed Sep 29 08:20:31 UTC 2021
On Wednesday, 29 September 2021 at 06:10:30 UTC, bauss wrote:
> 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 ~ "`");
> }
> ```
`inputRangeObject` already does something like that, but there
lies the problem. It means that you cannot wrap a range with
immobile elements in any of the `std.range.primitives` at all,
even if you never move them.
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.
More information about the Digitalmars-d
mailing list