[Issue 6207] Mixin template evaluated to string can convert to string mixin expression implicitly
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Oct 16 18:59:33 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6207
--- Comment #1 from Kenji Hara <k.hara.pg at gmail.com> 2011-10-16 18:58:34 PDT ---
We can improve the string lambda features in std.algorithm!
mixin template map(string pred)
{
enum map = `map!((a){ return `~pred~`; })`;
}
template map(alias pred)
{
auto map(E)(E[] r)
{
E[] result;
foreach (e; r)
result ~= pred(e);
return result;
}
}
void main()
{
int b = 10;
auto r = map!q{ a * b }([1,2,3]);
// --> mixin(`map!((a){ return ` ~ q{ a * b } ~ `; })`)([1,2,3])
// --> map!((a){ return a * b ; })([1,2,3]);
assert(r == [10,20,30]);
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list