UDAs - Restrict to User Defined Types?
Walter Bright
newshound2 at digitalmars.com
Thu Nov 8 21:10:55 PST 2012
On 11/8/2012 8:18 PM, Adam D. Ruppe wrote:
> On Friday, 9 November 2012 at 03:45:11 UTC, Nick Sabalausky wrote:
>> the *one* thing I hate about D ranges is that they don't force you to
>> explicitly say "Yes, I *intend* this to be an InputRange" (what are we, Go
>> users?).
>
> Just a note, of course it still wouldn't *force*, but maybe it'd be a good habit
> to start writing this:
>
> struct myrange {...}
> static assert(isInputRange!myrange);
>
> It'd be a simple way to get a check at the point of declaration and to document
> your intent.
>
>
> Interestingly, we could also do this if the attributes could run through a
> template:
>
> [check!isInputRange] struct myrange{}
>
> @attribute template check(something, Decl) {
> static assert(something!Decl);
> alias check = Decl;
> }
Many algorithms (at least the ones in Phobos do) already do a check to ensure
the inputs are the correct kind of range. I don't think you'll get very far
trying to use a range that isn't a range.
Of course, you can always still have bugs in your range implementation.
More information about the Digitalmars-d
mailing list