UDAs - Restrict to User Defined Types?
Jonathan M Davis
jmdavisProg at gmx.com
Thu Nov 8 21:24:49 PST 2012
On Thursday, November 08, 2012 21:10:55 Walter Bright wrote:
> 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.
Given that a range requires a very specific set of functions, I find it highly
unlikely that anything which isn't a range will qualify as one. It's far more
likely that you screw up and a range isn't the right kind of range because one
of the functions wasn't quite right.
There is some danger in a type being incorrectly used with a function when
that function requires and tests for only one function, or maybe when it
requires two functions. But I would expect that as more is required by a
template constraint, it very quickly becomes the case that there's no way that
any type would ever pass it with similarly named functions that didn't do the
same thing as what they were expected to do. It's just too unlikely that the
exact same set of function names would be used for different things, especially
as that list grows. And given that ranges are a core part of D's standard
library, I don't think that there's much excuse for having a type that has the
range functions but isn't supposed to be a range. So, I really don't see this
as a problem.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list