Choosing arity of a template function
Jonathan M Davis via Digitalmars-d
digitalmars-d at puremagic.com
Fri Feb 26 16:03:59 PST 2016
On Friday, 26 February 2016 at 23:11:32 UTC, Andrei Alexandrescu
wrote:
> Urgh, forgot the "static" in front of the second "if". It does
> work now. Nevertheless, I'm still on lookout for a more elegant
> solution! I have this mindset that using __traits(compiles) is
> some sort of cheating.
There's nothing cheating about using __traits(compiles). It's
basically the same as using is(typeof(foo)) and
is(typeof({statement;})), albeit arguably a bit more explicit
about the fact that it's testing what compiles. And there are
plenty of cases where one of those is exactly what code should be
doing.
Now, if it's a test that needs to be done frequently, then it
makes sense to create a wrapper for it that makes using it
cleaner, so I think that you're right in the sense that we should
be looking to have reusable traits to test with rather than using
__traits(compiles) or is(typeof(blah)) heavily, but they're still
fine to use when the occasion calls for it - especially if the
test in question isn't something that's going to need to be done
in much code. So, to a great extent, the question is whether what
you're trying to do here is something that very many folks are
going to want to do, and if it is, then we should find a way to
do it without __traits(compiles), but if not, then I'm not sure
that I'd worry much about it.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list