Created
June 6, 2015 21:48
-
-
Save rootid/1a4f4ae40116dbbbcac3 to your computer and use it in GitHub Desktop.
Functor template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<vector> | |
#include<algorithm> | |
using namespace std; | |
class X { | |
public : | |
void op() { | |
cout << "X::op() " << endl; | |
} | |
}; | |
//overrides the operator () | |
class Functor { | |
public : | |
void operator() (X &elem) { | |
elem.op(); | |
} | |
}; | |
int main () { | |
vector<X> v; | |
v.push_back(X()); | |
v.push_back(X()); | |
Functor f; | |
for_each (v.begin(),v.end(),f); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment