Skip to content

Instantly share code, notes, and snippets.

@sithhell
Created March 28, 2012 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sithhell/2224920 to your computer and use it in GitHub Desktop.
Save sithhell/2224920 to your computer and use it in GitHub Desktop.
Suggested phoenix solution -- getting rid of binding functions alltogether
#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