Choosing arity of a template function

Meta via Digitalmars-d digitalmars-d at puremagic.com
Fri Feb 26 21:23:04 PST 2016


It isn't cheating but IMO it's bad form. If you can do it without 
__traits(compiles) (or is(typeof()), etc.) you should, because 
there are many reasons why something will not compile, and only 
one of those reasons is the one you want to know. If there's no 
way around using it, you should still try to limit what is passed 
to __traits(compiles).

enum hasFront(T) = __traits(compiles, { auto _ = T.init.font; });

It's fairly easy to spot such a typo when it's only one line, but 
the risk of having some other compiler error being the reason 
your static if branch isn't taken grows very quickly with each 
additional line or bit of complexity.


More information about the Digitalmars-d mailing list