digitalmars.D.learn - Fastest way to check if a predicate can take a single parameter of a
- Per =?UTF-8?B?Tm9yZGzDtnc=?= (10/10) Oct 11 2019 I want to check whether
- Paul Backus (7/17) Oct 11 2019 Seems like the second one requires strictly less semantic
I want to check whether auto _ = pred(T.init); static assert(is(typeof(_) == bool)); compiles or not. Which one __traits(compiles, { auto _ = pred(T.init); static assert(is(typeof(_) == bool)); }) and is(typeof(pred(T.init)) == bool) is preferred compilation performance-wise?
Oct 11 2019
On Friday, 11 October 2019 at 09:05:25 UTC, Per Nordlöw wrote:I want to check whether auto _ = pred(T.init); static assert(is(typeof(_) == bool)); compiles or not. Which one __traits(compiles, { auto _ = pred(T.init); static assert(is(typeof(_) == bool)); }) and is(typeof(pred(T.init)) == bool) is preferred compilation performance-wise?Seems like the second one requires strictly less semantic analysis and is shorter and easier to read, so I'd go with that. Note that `pred(T.init)` will fail if pred accepts its argument by ref. If you want to handle that case, you have to do something like is(ReturnType!((T arg) => pred(arg)) == bool))
Oct 11 2019