Created
March 28, 2012 09:01
-
-
Save sithhell/2224920 to your computer and use it in GitHub Desktop.
Suggested phoenix solution -- getting rid of binding functions alltogether
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 <boost/assign/std/vector.hpp> | |
#include <boost/phoenix.hpp> | |
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
template <typename F> | |
void g(F const & f) | |
{ | |
f(); | |
} | |
BOOST_PHOENIX_ADAPT_FUNCTION(void, lazy_g, g, 1); | |
void f(int x) { | |
std::cout << "x is " << x << std::endl; | |
} | |
BOOST_PHOENIX_ADAPT_FUNCTION(void, lazy_f, f, 1); | |
using namespace boost::assign; | |
int main( ) | |
{ | |
using boost::phoenix::bind; | |
using boost::phoenix::lambda; | |
using boost::phoenix::placeholders::_1; | |
using boost::phoenix::local_names::_a; | |
std::vector<int> v; | |
v += 0,1,2,3,4,5,6; | |
std::for_each( v.begin( ), v.end( ), lazy_g(lambda(_a = _1)[lazy_f(_a)])); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment