Few recent dmd pull requests

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Thu Jun 26 07:53:04 PDT 2014


On Thu, Jun 26, 2014 at 02:45:05PM +0000, bearophile via Digitalmars-d wrote:
> H. S. Teoh:
> 
> >What's wrong with just writing auto?
> >
> >	auto sqr = a => a^^2;
> >	auto r = [1,2,3].map!sqr;
> 
> auto is used to use the type of the value on the right. But "a =>
> a^^2" is not a value, it can't be assigned to a variable, because it's
> not a lambda.
> 
> To use auto you need to give a type, creating a lambda:
> 
> auto sqr = (int a) => a ^^ 2;
[...]

Oh I see, you want the argument type to be generic?

This works with dmd git HEAD:

	import std.algorithm : map;
	static sqr(A)(A a) { return a^^2; }
	auto r1 = [1,2,3].map!sqr;
	auto r2 = [1.0, 2.0, 3.0].map!sqr;

It's a little more verbose, though.


T

-- 
The easy way is the wrong way, and the hard way is the stupid way. Pick one.


More information about the Digitalmars-d mailing list