www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Example for multi level template composition

reply Arun <aruncxy gmail.com> writes:
Stumbled upon this question on HN 
https://news.ycombinator.com/item?id=33142751#33147401

 Can I write template A and then apply it to itself to get 
 template B and then apply that onto template C to get template 
 D.
Does anyone have an example for this?
Oct 09 2022
next sibling parent user1234 <user1234 12.de> writes:
On Monday, 10 October 2022 at 06:30:05 UTC, Arun wrote:
 Stumbled upon this question on HN 
 https://news.ycombinator.com/item?id=33142751#33147401

 Can I write template A and then apply it to itself to get 
 template B and then apply that onto template C to get template 
 D.
Does anyone have an example for this?
Recursive templates can make other templates with themselves. I dont feel to provide an example ATM tho.
Oct 10 2022
prev sibling next sibling parent rassoc <rassoc posteo.de> writes:
On 10/10/22 08:30, Arun via Digitalmars-d-learn wrote:
 Stumbled upon this question on HN
https://news.ycombinator.com/item?id=33142751#33147401
 
 Can I write template A and then apply it to itself to get template B and then
apply that onto template C to get template D.
Does anyone have an example for this?
Aren't UFCS chained range calls just that? range.map!foo.filter!bar.fold!baz; These templates return new template ranges that transform themselves according to their inputs via Design by Introspection. For example, joiner of joiner of joiner would allow you to lazily flatten a multi dim array.
Oct 10 2022
prev sibling next sibling parent ag0aep6g <anonymous example.com> writes:
On Monday, 10 October 2022 at 06:30:05 UTC, Arun wrote:
 Stumbled upon this question on HN 
 https://news.ycombinator.com/item?id=33142751#33147401

 Can I write template A and then apply it to itself to get 
 template B and then apply that onto template C to get template 
 D.
Does anyone have an example for this?
You can just write that down in code: ```d template D() { enum D = "It's me, template D!"; } template A(alias MyA) { template A(alias MyC) { alias A = D; } } template C() {} alias B = A!A; alias MaybeD = B!C; pragma(msg, MaybeD!()); /* prints "It's me, template D!" */ ```
Oct 10 2022
prev sibling parent surlymoor <surlymoor cock.li> writes:
On Monday, 10 October 2022 at 06:30:05 UTC, Arun wrote:
 Stumbled upon this question on HN 
 https://news.ycombinator.com/item?id=33142751#33147401
This guy could have read std.meta's documentation or source, but instead makes assumptions and lazes around.
Oct 10 2022