Skip to content

Instantly share code, notes, and snippets.

@zhangyuchi
Last active August 29, 2015 14:09
Show Gist options
  • Save zhangyuchi/240079c94aff4174335c to your computer and use it in GitHub Desktop.
Save zhangyuchi/240079c94aff4174335c to your computer and use it in GitHub Desktop.
boost transform bind sample
struct Myclass
{
std::string getFirstString() {return string1}
std::string getSecondString() {return string2}
private:
std::string string1;
std::string string2;
}
Myclass myObj;
std::vector<string > newVec;
std::vector<myObj> oldVec;
#include <boost/bind.hpp>
std::transform(oldVec.begin(), oldVec.end(),
std::back_inserter(newVec),
boost::bind(std::plus<std::string>(),
boost::bind(&Myclass::getFirstString, _1),
boost::bind(&Myclass::getSecondString, _1)
)
);
#include <boost/lambda/bind.hpp>
namespace rg = boost::range;
namespace ll = boost::lambda;
rg::transform(oldVec, std::back_inserter(newVec),
ll::bind(&Myclass::getFirstString, ll::_1) +
ll::bind(&Myclass::getSecondString, ll::_1));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment