Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Shorting in one line using class members std and boost bind
//Sorting in one line using class members std and boost phoenix #include <iostream> #include <string> #include <vector> #include <algorithm> #include <boost/phoenix/phoenix.hpp> struct Parent{ int getAge() const{ return age; } int getYear() const{ return year; } int age; int year; std::string name; }; int main() { std::vector<Parent> aListParents; Parent aParent1; aParent1.age=1; aParent1.year=2; aParent1.name="parent1"; Parent aParent2; aParent2.age=2; aParent2.year=1; aParent2.name="parent2"; aListParents.push_back(aParent2); aListParents.push_back(aParent1); aListParents.push_back(aParent2); aListParents.push_back(aParent1); for_each(aListParents.begin(), aListParents.end(), std::cout << boost::phoenix::bind(&Parent::name, boost::phoenix::placeholders::arg1) << ' '); std::sort(aListParents.begin(), aListParents.end(), boost::phoenix::bind(&Parent::getAge, boost::phoenix::placeholders::arg1) < boost::phoenix::bind(&Parent::getAge, boost::phoenix::placeholders::arg2)); std::cout << "\n After sorting age:" << std::endl; for_each(aListParents.begin(), aListParents.end(), std::cout << boost::phoenix::bind(&Parent::name, boost::phoenix::placeholders::arg1) << ' '); std::sort(aListParents.begin(), aListParents.end(), boost::phoenix::bind(&Parent::getYear, boost::phoenix::placeholders::arg1) < boost::phoenix::bind(&Parent::getYear, boost::phoenix::placeholders::arg2)); std::cout << "\n After sorting by year:" << std::endl; for_each(aListParents.begin(), aListParents.end(), std::cout << boost::phoenix::bind(&Parent::name, boost::phoenix::placeholders::arg1) << ' '); }
run
|
edit
|
history
|
help
0
scemo dd
multi bitmap
int divide by int
c1
Dec to Bin
Привет Linux
friend function
Shultz_Lab1.CPP
test
numberOftweets