On 23/05/2015 7:48 a.m., Jonathan M Davis wrote:
On Friday, 22 May 2015 at 19:44:59 UTC, H. S. Teoh wrote:
On Fri, May 22, 2015 at 12:39:12PM -0700, H. S. Teoh via Digitalmars-d
wrote:
[...]
face.palm();
head.hang!inShame();
self.crawlBackTo(hole);
[...]
Truth be told, though, the error message was very unhelpful about it. It
just says no templates were matched, no indication about the fact that
the problem was caused by mismatched type lengths.
Well, I'm not sure how we could fix that. That's a general problem with
template constraints. You know that they aren't passing, but you don't
know _why_ they aren't passing. Though maybe in this case, the docs
could be improved to make it clearer that if you're getting compilation
errors, there's a decent chance that you got the type sizes wrong.
- Jonathan M Davis
template X(T, string v) if (is(T == class) && v.length == 2) {
} else {
pragma(msg, "X must have two template arguments, where the first is a
class symbol and the second is a string with a length of two characters.");
}
Or
template X() if (false) {
pragma(msg, "X must have two template arguments, where the first is a
class symbol and the second is a string with a length of two characters.");
}
Humm, the first would be abused a lot. The second would be highly
limiting. The first, but all overloads must be in the style of if, else
template, else. But how to limit it to one name..
Anyway just some random thoughts.