Re: Trying to understand map being a template

2024-01-09 Thread Noé Falzon via Digitalmars-d-learn
Thank you very much for your answers. The point I had mostly misunderstood was alias template parameters, which make this possible.

Re: Trying to understand map being a template

2024-01-06 Thread FeepingCreature via Digitalmars-d-learn
On Saturday, 6 January 2024 at 17:57:06 UTC, Paul Backus wrote: On Friday, 5 January 2024 at 20:41:53 UTC, Noé Falzon wrote: In fact, how can the template be instantiated at all in the following example, where no functions can possibly be known at compile time: ``` auto do_random_map(int dele

Re: Trying to understand map being a template

2024-01-06 Thread Paul Backus via Digitalmars-d-learn
On Friday, 5 January 2024 at 20:41:53 UTC, Noé Falzon wrote: In fact, how can the template be instantiated at all in the following example, where no functions can possibly be known at compile time: ``` auto do_random_map(int delegate(int)[] funcs, int[] values) { auto func = funcs.choi

Re: Trying to understand map being a template

2024-01-05 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 05, 2024 at 08:41:53PM +, Noé Falzon via Digitalmars-d-learn wrote: > On the subject of `map` taking the function as template parameter, I > was surprised to see it could still be used with functions determined > at runtime, even closures, etc. I am trying to understand the > mecha

Trying to understand map being a template

2024-01-05 Thread Noé Falzon via Digitalmars-d-learn
On the subject of `map` taking the function as template parameter, I was surprised to see it could still be used with functions determined at runtime, even closures, etc. I am trying to understand the mechanism behind it. The commented out line causes the error that `choice(funcs)` cannot be