Re: Template pattern delegate?

2020-10-26 Thread frame via Digitalmars-d-learn
On Monday, 26 October 2020 at 09:25:03 UTC, Jacob Carlborg wrote: On Monday, 26 October 2020 at 00:56:26 UTC, frame wrote: If you pass the delegate as a template parameter/alias parameter, it's more likely to be inlined: auto myStuff(alias fn)() { try return fn(); catch (Exception

Re: Template pattern delegate?

2020-10-26 Thread Jacob Carlborg via Digitalmars-d-learn
On Monday, 26 October 2020 at 00:56:26 UTC, frame wrote: I see that your approach can handle functions and delegates but isn't that not equivalent like this template for a function? auto myStuff(T)(T function() fn) { try { return fn(); } catch (Exception e) { //

Re: Template pattern delegate?

2020-10-25 Thread frame via Digitalmars-d-learn
On Sunday, 25 October 2020 at 12:02:10 UTC, Ali Çehreli wrote: On 10/25/20 4:30 AM, frame wrote: Is there a possibility to write templated code / custom trait pattern with usage like a delegate? I have a try-catch block with different types and don't want to repeat myself in every method

Re: Template pattern delegate?

2020-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/20 4:30 AM, frame wrote: Is there a possibility to write templated code / custom trait pattern with usage like a delegate? I have a try-catch block with different types and don't want to repeat myself in every method again. It's always the same, just what's tried changes, eg.:

Template pattern delegate?

2020-10-25 Thread frame via Digitalmars-d-learn
Is there a possibility to write templated code / custom trait pattern with usage like a delegate? I have a try-catch block with different types and don't want to repeat myself in every method again. It's always the same, just what's tried changes, eg.: pseudo code: template myStuff(mixin