Forward ranges in Phobos v2
Adam D Ruppe
destructionator at gmail.com
Wed Nov 3 16:48:14 UTC 2021
On Wednesday, 3 November 2021 at 15:59:40 UTC, Steven
Schveighoffer wrote:
> Oh, and one more thing, if we are going to do a tag, a UDA is
> probably a more asthetic and functional tag. e.g. it doesn't
> affect `__traits(allMembers, T)`.
Best way is to make the decoration also be a check. A UDA can do
it:
---
template InputRange(Ty = void) {
static if(is(Ty == void)) alias T = typeof(this); else
alias T = Ty;
static import std.range;
static assert(std.range.isInputRange!T, "more informative
message");
enum isInputRange = true;
}
@InputRange!MyRange
struct MyRange {
bool empty;
int front;
//void popFront() {}
//mixin InputRange;
}
---
That silly one works as either a mixin or a UDA each with
stylistic pros and cons, but the functionality benefit of a
concrete check of intention and nice error messages before
granting you the tag would legitimately be really quite nice.
More information about the Digitalmars-d
mailing list