KeyType, ValueType traits for hashes
mail.mantis.88 at gmail.com
Tue Jan 24 12:18:29 PST 2012
24.01.2012 20:49, bearophile пишет:
>> Of course, most likely that user already did type check, but if not,
>> this will give less cryptic error:
>> Error: static assert "Not associative array: int"
>> instantiated from here: KeyType!(int)
>> , instead of:
>> Error: template instance KeyType!(int) KeyType!(int) does not match
>> template declaration KeyType(AA) if (isAssociativeArray!(AA))
> It's a tradeoff. Your custom error message is more readable, but the failure at the template constraint causes a error line at the instantiation point. Sadly I think there is no solution that solves both problems (we have stack traces for templates, but...).
True. Maybe something is possible to achieve in this direction?:
template verboseFail(alias Cond, string message)
static if (Cond)
enum verboseFail = true;
pragma( msg, message );
enum verboseFail = false;
if (verboseFail!(isAssociativeArray!AA, "Not assosiative array: " ~
static if (is(AA V : V[K], K))
alias K KeyType;
It doesn't work very nicely (the message is logged, but dos not look as
it is related to error), but perharps it may be improved somehow?
More information about the Digitalmars-d-learn