<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">__traits(compiles...) does not call your function so it is not evaluate twice only once, so there is no need to use memoize<br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Nov 23, 2018 at 11:35 AM John Chapman via Digitalmars-d-learn <<a href="mailto:digitalmars-d-learn@puremagic.com">digitalmars-d-learn@puremagic.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'm doing a fair amount of repeatedly checking if a function <br>
compiles with __traits(compiles...), executing the function if <br>
so, erroring out if not, like this:<br>
<br>
   static if (__traits(compiles, generateFunc1())) {<br>
     return generateFunc1();<br>
   } static if (__traits(compiles, generateFunc2())) {<br>
     return generateFunc2();<br>
   } else static assert(false);<br>
<br>
But it seems inefficient to have to evaluate those functions <br>
twice, so I'd like to optimise this so if __traits(compiles...) <br>
succeeds, the result is cached and then used when the function is <br>
actually called. I wondered if using std.functional.memoize would <br>
help?<br>
</blockquote></div>