Equivalent of C++ std::function

Yuushi via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 24 18:10:45 PDT 2014


I was wondering if D had something akin to std::function in C++.

Say I have some functions in an associative array, for example:

      auto mapping = ['!' : (string a) => toUpper!string(a), '^' : 
(string a) => capitalize!string(a)];

What I want to do is basically declare something like:

     function string(string) transform;
     if(<some condition>) {
          transform = mapping[<lookup>];
     }

In C++, this could be done by declaring:

      std::function<string(string)> transform;

Is there an equivalent D construct for this?


More information about the Digitalmars-d-learn mailing list