std.algorithm issue
bearophile
bearophileHUGS at lycos.com
Wed May 21 16:41:26 PDT 2008
Brian Myers:
> Is it possible to map! or reduce! a member function or delegate against a
> range? If so how would I do that?
Do you mean something like this?
import d.func: map, xrange, putr;
class Foo {
int sqr(int x) { return x * x; }
}
class Baz {
float div2(int x) { return x / 2; }
}
void main() {
auto f1 = new Foo;
putr( map(&f1.sqr, xrange(10)) );
auto b1 = new Baz;
putr( map(&b1.div2, xrange(10)) );
}
Output:
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
[0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0]
Bye,
bearophile
More information about the Digitalmars-d
mailing list