How to use map?

Lemonfiend via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Nov 11 05:24:52 PST 2014


I'm trying to do something simple like creating an array of 
struct S from a float array via map:

---
void main()
{
	float[] vals = [1.1, 2.1, 3.1, 4.1];

	import std.algorithm: map;
	auto arr = vals.map!`S(a)`.array;
	writeln(arr);
}

struct S(T)
{
	T t;
}
---

But I get:
---
C:\D\dmd2\windows\bin\..\..\src\phobos\std\functional.d-mixin-49(49): 
Error: undefined identifier S
C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d(480): 
Error: template instance std.functional.unaryFun!("S(a)", 
"a").unaryFun!float error instantiating
C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d(427):      
   instantiated from here: MapResult!(unaryFun, float[])
src\app.d(28):        instantiated from here: map!(float[])
---

If I instead do ie. map!`cast(int)a` it works fine.
What am I missing?


More information about the Digitalmars-d-learn mailing list