memoize & __traits(compiles...)
Daniel Kozak
kozzi11 at gmail.com
Fri Nov 23 11:36:52 UTC 2018
__traits(compiles...) does not call your function so it is not evaluate
twice only once, so there is no need to use memoize
On Fri, Nov 23, 2018 at 11:35 AM John Chapman via Digitalmars-d-learn <
digitalmars-d-learn at puremagic.com> wrote:
> I'm doing a fair amount of repeatedly checking if a function
> compiles with __traits(compiles...), executing the function if
> so, erroring out if not, like this:
>
> static if (__traits(compiles, generateFunc1())) {
> return generateFunc1();
> } static if (__traits(compiles, generateFunc2())) {
> return generateFunc2();
> } else static assert(false);
>
> But it seems inefficient to have to evaluate those functions
> twice, so I'd like to optimise this so if __traits(compiles...)
> succeeds, the result is cached and then used when the function is
> actually called. I wondered if using std.functional.memoize would
> help?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20181123/0402c52f/attachment.html>
More information about the Digitalmars-d-learn
mailing list