Created
June 29, 2021 02:43
-
-
Save emadflash/42e74a04df1bbc6a300fb5b7add1f0da 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
#include <iostream> | |
#include <iterator> | |
#include <vector> | |
#include <algorithm> | |
#include <functional> | |
using namespace std; | |
template<typename It, typename OutIt> | |
OutIt printContainer(It begin, It end, OutIt ot) { | |
for(auto it=begin; it != end; ++it) { | |
*ot++ = *it; | |
} | |
return ot; | |
} | |
template<typename It, typename OutIt, typename Func> | |
OutIt printContainer(It begin, It end, OutIt ot, Func F) { | |
for(auto it=begin; it != end; ++it) { | |
if (F(*it)) { | |
*ot++ = *it; | |
} | |
} | |
return ot; | |
} | |
int main() { | |
vector<int> v { 1, 4, 5, 19, 2 }; | |
printContainer(v.begin(), v.end(), ostream_iterator<int>(cout, " "), [](auto x) { | |
if(x % 2 == 0) { | |
return true; | |
} | |
return false; | |
}); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment