Skip to content

Instantly share code, notes, and snippets.

@kbob
Created February 9, 2011 01:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kbob/817744 to your computer and use it in GitHub Desktop.
Save kbob/817744 to your computer and use it in GitHub Desktop.
// C++
// ref. https://gist.github.com/817504
#include <algorithm>
#include <iterator>
#include <vector>
using namespace std;
class counter {
public:
typedef int result_type;
counter(int start) : n(start) {}
result_type operator()() { return n++; }
private:
result_type n;
};
vector<int> f()
{
vector<int> v;
generate_n(back_inserter(v), 4, counter(1));
v.resize(distance(v.begin(),
remove_if(v.begin(), v.end(),
bind2nd(modulus<int>(), 2))));
return v;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment