pointer to member without 'this' - mem_fun like
Vlad
b100dian at gmail.com
Tue Mar 18 06:03:08 PDT 2008
Derek Parnell wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Tue, 18 Mar 2008 11:27:23 +0200, Vlad wrote:
>
>> Hi list,
>>
>> I was wondering if D has something like C's mem_fun, where one can pass
>> a pointer to a member function of a class, that later can be called with
>> various 'this' instances.
>
> Excuse my ignorance, but what is the benefit of this technique?
>
> - --
> Derek Parnell
Example: writing a map()-like function that works on a collection of
objects and calling a method on them, instead of a free function
Pseudocode:
(with a 'free function'):
string in[] = ...
int out[] = map (in, len);
(with a 'member_fun'):
T in[] = ...
T out[] = map(in, &T.do_something);
or even:
T in[] = ...
int out[] = map(in, &T.get_some_int_property)
More information about the Digitalmars-d-learn
mailing list