Created
February 9, 2011 01:56
-
-
Save kbob/817744 to your computer and use it in GitHub Desktop.
This file contains 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
// 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