Last active
August 29, 2015 14:09
-
-
Save zhangyuchi/240079c94aff4174335c to your computer and use it in GitHub Desktop.
boost transform bind sample
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
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