Skip to content

Instantly share code, notes, and snippets.

@rootid
Created June 6, 2015 21:48
Show Gist options
  • Save rootid/1a4f4ae40116dbbbcac3 to your computer and use it in GitHub Desktop.
Save rootid/1a4f4ae40116dbbbcac3 to your computer and use it in GitHub Desktop.
Functor template
#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