std.algorithm issue
Brian Myers
bmyers at harryanddavid.com
Thu May 22 11:35:53 PDT 2008
I think this is exactly what I wanted. I needed to use the address of operator along with the instance reference.
Wow some of the things you can do in D (like Dee Girl's post) are almost as esoteric and obscure as Felix!
Thanx everyone,
Brian
bearophile Wrote:
> 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