Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

I don't even

Name: Anonymous 2011-04-12 12:24

You have 2 minutes to explain functors. Examples should be in sepples.

Name: i_wear_my_moms_pantyhose 2011-04-12 12:34

Functors is something that the unabomber studied while pursuing his Ph.D in Mathematics.

Name: m not a group of hacker 2011-04-12 12:46

I'm not a group of hacker

Name: Anonymous 2011-04-12 12:56

If OP were serious he would request this knowledge in Haskell.

Name: Anonymous 2011-04-12 14:00

If OP were serious he would request this knowledge in Fortran.

Name: Anonymous 2011-04-12 14:25

If OP were serious he would request this knowledge in Delphi 2010.

Name: Anonymous 2011-04-12 18:02

Functors are class types which behave like functions. This is accomplished by overloading operator(). Functors can capture and retain state between invocations, and so can be used to implement closures. In fact, C++11 lambda functions actually generate a nameless functor class type which captures variables as members, generates a copy constructor and assignment operator to copy the members by value or reference depending on how you bound the variables to the closure, and implements operator().


#include <cstdio>

class MultiplyBy
{
public:

    explicit MultiplyBy(int x) : value(x) { }
    int operator()(int y) { return value * y; }

private:

    int value;
};

int main(int, char**) {
    MultiplyBy func(5);
    std::printf("5 * 2 = %d\n", func(2));
    return 0;
}

Name: Anonymous 2011-04-13 4:42

>>7
Why would you help an impolite person like >>1?
It makes fucktards like >>1 think that not asking nicely is acceptable.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List