Created
September 6, 2012 09:59
-
-
Save kennethho/3654186 to your computer and use it in GitHub Desktop.
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
// $ g++ -std=c++0x filter.cpp | |
#include <iterator> | |
#include <algorithm> | |
template <class Sequence, class Predicate> | |
Sequence filter(const Sequence& seq, Predicate pred) | |
{ | |
Sequence result; | |
std::copy_if(begin(seq), end(seq), back_inserter(result), pred); | |
return result; | |
} | |
#include <string> | |
#include <list> | |
using namespace std; | |
int main() | |
{ | |
list<string> l = {"Hello ", "", "world"}; | |
l = filter(l, [](const string& s) { return !s.empty(); }); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment