Metaprogramming in D : Some Real-world Examples
grauzone
none at example.net
Wed Nov 11 08:23:29 PST 2009
Don wrote:
> Christopher Wright wrote:
>> grauzone wrote:
>>> You're not testing for types, you're testing if it compiles. Inside
>>> the tested block of code, all sorts of things could go wrong. You
>>> can't know if is(typeof(...)) really did what you wanted, or if
>>> something broke.
>
> You're testing, "is everything inside that OK?". If you want to know WHY
> it's wrong, you'd better make sure you're testing something simple.
Andrei's range lib uses it more in a way "does this type support this
and that range interface?". Example:
http://dsource.org/projects/phobos/browser/trunk/phobos/std/range.d#L58
>> So it requires caution, and you want to keep the contents small. It's
>> useful, but it requires caution.
>
> I don't even think it particularly requires caution. If it passes, you
> know everything is OK. It's just that it's an all-or-nothing test.
And if it doesn't pass, you know something is not ok? Then shouldn't you
raise an error? Oh wait...
> IMHO, one of the best features of it, is that you can have negative
> compile-time unit tests. You can create tests which must be rejected at
> compile time. I don't know of any other clean way to do that.
True; that's another use of this feature.
More information about the Digitalmars-d-announce
mailing list