Created
January 2, 2018 21:49
-
-
Save joboccara/381634cd93fcba7ff3c9a6957f4047b7 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
#include <algorithm> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include <boost/phoenix/phoenix.hpp> | |
struct isEvenImpl | |
{ | |
template<typename Arg> | |
bool operator()(Arg arg) const | |
{ | |
return arg % 2 == 0; | |
} | |
}; | |
boost::phoenix::function<isEvenImpl> isEven; | |
int main() | |
{ | |
using namespace boost::phoenix::placeholders; | |
using boost::phoenix::val; | |
std::vector<int> numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9}; | |
std::vector<int> multiples5 = {5, 10, 15, 20, 25, 30, 35, 40, 45}; | |
std::vector<int> results; | |
std::for_each(begin(numbers), end(numbers), | |
if_(isEven(arg1)) | |
[ | |
std::cout << val("Even ") | |
]. | |
else_ | |
[ | |
std::cout << val("Odd ") | |
]); | |
std::cout << '\n' << '\n'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment