Tom S:
>I'd be more than happy to see some wider support from D in this regard,<
If no one discusses about this, things aren't going to improve. I'll post
something related to this to the main D newsgroup soon.
>Ah well, SFINAE fails here :P<
But the interesting question is why does it fail? It seems a bug of DMD, not a
bug in that code.
>No sane person will be using these for strings anyway ;) The traits are used
>mostly to be inline documentation <about what features the user defined type
>must provide.<
It looks like generic library code, so you can't assume a sane person, so I
suggest you to put unittests, that contain such case too. You may even add a
static if to work around such "common" bug (I know, isSummable() is absent from
your code):
template isSummable(T) {
// BUG: IsArray!(T) is added to patch a possible bug of DMD v.1.036
const bool isSummable = !IsArray!(T) && is(typeof(T.init + T.init));
}
template isRingType(T) {
const bool isRingType = isSummable!(T) &&
is(typeof(T.init - T.init)) &&
is(typeof(T.init * T.init));
}
template isFieldType(T) {
const bool isFieldType = isRingType!(T) && is(typeof(T.init / T.init));
}
Writing very reliable "library" code (bulletproof, if possible) avoids you bugs
later in all the code that uses that library code. Adding lot of unittests
(covering even weird corner cases) to every function, class and template helps.
Bye,
bearophile