www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - lambda template literals?

reply bearophile <bearophileHUGS lycos.com> writes:
Is code vaguely like this meaningful and useful?


void main() {
    alias (x => x ^^ 2) sqrTemplate;
}


Bye,
bearophile
Jan 17 2012
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 01/18/2012 01:35 AM, bearophile wrote:
 Is code vaguely like this meaningful and useful?


 void main() {
      alias (x =>  x ^^ 2) sqrTemplate;
 }


 Bye,
 bearophile
Yes. The fact that your particular example does not work is a mere syntactic issue. This works: template ID(alias a){alias a ID;} void main(){ alias ID!(x => x ^^ 2) sqrTemplate; }
Jan 17 2012
parent reply bearophile <bearophileHUGS lycos.com> writes:
Timon Gehr:

 Yes. The fact that your particular example does not work is a mere 
 syntactic issue.
 This works:
 
 template ID(alias a){alias a ID;}
 void main(){
      alias ID!(x => x ^^ 2) sqrTemplate;
 }
Thank you Timon, you are often good :-) I'll add it as enhancement request. Bye, bearophile
Jan 17 2012
parent reply Philippe Sigaud <philippe.sigaud gmail.com> writes:
On Wed, Jan 18, 2012 at 02:06, bearophile <bearophileHUGS lycos.com> wrote:

 template ID(alias a){alias a ID;}
 void main(){
 =C2=A0 =C2=A0 =C2=A0alias ID!(x =3D> x ^^ 2) sqrTemplate;
 }
Thank you Timon, you are often good :-) I'll add it as enhancement request.
This limitation (not being able to alias a lambda) is quite irksome. If you do an enhancement request, could you also add one for: alias __traits(whatever, whatever) some Result; Right now, the alias grammar doesn't allow this and I find this limitation jarring.
Jan 18 2012
parent bearophile <bearophileHUGS lycos.com> writes:
Philippe Sigaud:

 This limitation (not being able to alias a lambda) is quite irksome.
 If you do an enhancement request, could you also add one for:
 
 alias __traits(whatever, whatever) some Result;
 
 Right now, the alias grammar doesn't allow this and I find this
 limitation jarring.
It's better to add it yourself: http://d.puremagic.com/issues/show_bug.cgi?id=7308 Bye, bearophile
Jan 18 2012