Compile time sequences
drug
drug2004 at bk.ru
Wed Oct 3 18:23:18 UTC 2018
On 03.10.2018 20:22, Paul Backus wrote:
>
> In my experience doing metaprogramming in D, it's best to make your
> static if/template constraint tests as narrow and specific as possible.
> For example, if you want to know whether you can call a function with a
> particular argument, you don't need to muck around with std.traits; you
> can just check whether the function call compiles:
>
> static if(__traits(compiles, f(arg))) {
> // do something with f(arg)
> }
>
> So my question to you is: why do you care whether something is a symbol
> or a value? Is there actually a more specific question that you're
> trying to answer with that information? If so, just ask the more
> specific question directly.
I did like you does. It failed. It's suitable for some local things, but
if you need more general solution it fails. You don't know why your code
doesn't compile. If `f` is template it can hurt because failed
instantiation may lead to wrong code path you don't expect. For example
your code has two paths - when the code compiles and doesn't. You or
someone else later adds template function like `f` but makes just typo
in function body - wrong code path taken and you won't know it until
start fixing bug somewhere else.
Now I prefer to use `hasMember` and also check args at least for length.
More specific question is that I distinct values and symbols by taking
address and it looks like hack for me. I'll try to show example later.
More information about the Digitalmars-d-learn
mailing list