Re: Understanding alias template parameters

2022-04-22 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 22 April 2022 at 08:04:16 UTC, JG wrote: On Thursday, 21 April 2022 at 21:02:47 UTC, JG wrote: Hi, Could someone possibly help me to understand why the commented line doesn't compile? Good job, works great! Potential is high: ```d void main() { alias type = real; auto rang

Re: Understanding alias template parameters

2022-04-22 Thread Ali Çehreli via Digitalmars-d-learn
On 4/22/22 01:04, JG wrote: > In response to the change to "alias", which has several upsides > including faster code. I would note it also has some downsides including > every lambda produces a new type so that (at the moment) the following > assert > holds: I got confused a little bit there. T

Re: Understanding alias template parameters

2022-04-22 Thread JG via Digitalmars-d-learn
On Thursday, 21 April 2022 at 21:02:47 UTC, JG wrote: Hi, Could someone possibly help me to understand why the commented line doesn't compile? ```d import std; struct MapResult(R,F) { R r; const F f; auto empty() { return r.empty; } auto front() { return f(r.front); } vo

Re: Understanding alias template parameters

2022-04-21 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 21, 2022 at 09:02:47PM +, JG via Digitalmars-d-learn wrote: > Hi, > > Could someone possibly help me to understand why the commented line > doesn't compile? > > > ```d > import std; > > struct MapResult(R,F) > { > R r; > const F f; > auto empty() { return r.empty; }

Re: Understanding alias template parameters

2022-04-21 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 21 April 2022 at 21:38:14 UTC, Ali Çehreli wrote: ```d auto myMap(alias f, R)(R r) { pragma(msg, typeof(f)); return MapResult!(R, f)(r); } ``` It looks delicious when the convenience function works magic with Voldemort: ```d import std.range, std.stdio; auto myMap(alias

Re: Understanding alias template parameters

2022-04-21 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 21 April 2022 at 21:02:47 UTC, JG wrote: Hi, Could someone possibly help me to understand why the commented line doesn't compile? ```d import std; struct MapResult(R,F) { R r; const F f; auto empty() { return r.empty; } auto front() { return f(r.front); } vo

Re: Understanding alias template parameters

2022-04-21 Thread Ali Çehreli via Digitalmars-d-learn
On 4/21/22 14:02, JG wrote: > Could someone possibly help me to understand why the commented line > doesn't compile? iota(10).myMap!(x=>2*x).writeln; It is because x=>2*x is just a template. I don't know why the compiler chooses 'void' for typeof(f) but apparently that's how it represents th

Understanding alias template parameters

2022-04-21 Thread JG via Digitalmars-d-learn
Hi, Could someone possibly help me to understand why the commented line doesn't compile? ```d import std; struct MapResult(R,F) { R r; const F f; auto empty() { return r.empty; } auto front() { return f(r.front); } void popFront() { r.popFront; } auto save() { return