Re: A look inside "filter" function defintion

2022-08-14 Thread Kyle Ingraham via Digitalmars-d-learn
On Tuesday, 2 August 2022 at 12:39:41 UTC, pascal111 wrote: but I'm still stuck. Do you have a down-to-earth example for beginners to understand this concept? I often go back to this post when writing templates: https://dlang.org/blog/2020/07/31/the-abcs-of-templates-in-d/ It helped me when

Re: A look inside "filter" function defintion

2022-08-09 Thread Meta via Digitalmars-d-learn
On Monday, 1 August 2022 at 23:35:13 UTC, pascal111 wrote: This is the definition of "filter" function, and I think it called itself within its definition. I'm guessing how it works? '''D template filter(alias predicate) if (is(typeof(unaryFun!predicate))) { /** Params: range =

Re: A look inside "filter" function defintion

2022-08-09 Thread Patrick Schluter via Digitalmars-d-learn
On Tuesday, 2 August 2022 at 12:39:41 UTC, pascal111 wrote: On Tuesday, 2 August 2022 at 04:06:30 UTC, frame wrote: On Monday, 1 August 2022 at 23:35:13 UTC, pascal111 wrote: This is the definition of "filter" function, and I think it called itself within its definition. I'm guessing how it

Re: A look inside "filter" function defintion

2022-08-09 Thread pascal111 via Digitalmars-d-learn
On Tuesday, 9 August 2022 at 18:23:04 UTC, Ali Çehreli wrote: On 8/2/22 05:39, pascal111 wrote: > I'm still stuck. Do you have a > down-to-earth example for beginners to understand this concept? I will refer to my explanation because down-to-earth has always been my goal. I hope i succeeded:

Re: A look inside "filter" function defintion

2022-08-09 Thread Ali Çehreli via Digitalmars-d-learn
On 8/2/22 05:39, pascal111 wrote: > I'm still stuck. Do you have a > down-to-earth example for beginners to understand this concept? I will refer to my explanation because down-to-earth has always been my goal. I hope i succeeded:

Re: A look inside "filter" function defintion

2022-08-03 Thread novice2 via Digitalmars-d-learn
leyts try very rough simlified concept: template itself - is compile-time program (parameterizable), it can generate some code for you. template instantiation (like "calling") with "!" - instruct compiler to "start this compile-time program here with this parameters".

Re: A look inside "filter" function defintion

2022-08-02 Thread frame via Digitalmars-d-learn
On Tuesday, 2 August 2022 at 14:58:52 UTC, pascal111 wrote: Maybe this helps: A template can be seen as a static struct too, so you can access its members with the scope operator "." and if there is only one member of the same name as the template ifself, the compiler auto completes it to

Re: A look inside "filter" function defintion

2022-08-02 Thread pascal111 via Digitalmars-d-learn
On Tuesday, 2 August 2022 at 14:24:50 UTC, frame wrote: On Tuesday, 2 August 2022 at 12:39:41 UTC, pascal111 wrote: Instantiation seems some complicated to me. I read "If a template contains members whose name is the same as the template identifier then these members are assumed to be

Re: A look inside "filter" function defintion

2022-08-02 Thread frame via Digitalmars-d-learn
On Tuesday, 2 August 2022 at 12:39:41 UTC, pascal111 wrote: Instantiation seems some complicated to me. I read "If a template contains members whose name is the same as the template identifier then these members are assumed to be referred to in a template instantiation:" in the provided link,

Re: A look inside "filter" function defintion

2022-08-02 Thread Andrey Zherikov via Digitalmars-d-learn
On Monday, 1 August 2022 at 23:35:13 UTC, pascal111 wrote: I think this line needs explanation: '''D return FilterResult!(unaryFun!predicate, Range)(range); ''' Create an object of type `FilterResult!(unaryFun!predicate, Range)` by passing `range` to its ctor, then return that object.

Re: A look inside "filter" function defintion

2022-08-02 Thread pascal111 via Digitalmars-d-learn
On Tuesday, 2 August 2022 at 04:06:30 UTC, frame wrote: On Monday, 1 August 2022 at 23:35:13 UTC, pascal111 wrote: This is the definition of "filter" function, and I think it called itself within its definition. I'm guessing how it works? It's a template that defines the function called

Re: A look inside "filter" function defintion

2022-08-01 Thread frame via Digitalmars-d-learn
On Monday, 1 August 2022 at 23:35:13 UTC, pascal111 wrote: This is the definition of "filter" function, and I think it called itself within its definition. I'm guessing how it works? It's a template that defines the function called "Eponymous Templates":