Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Boost phoenix. e.g 2: functor
//Boost phoenix. e.g 2: functor #include <iostream> #include <string> #include <vector> #include <algorithm> // #include <boost/phoenix/phoenix.hpp> class Person { public: std::string getName() const { return _name; } std::string getAge() const { return _age; } void setName(std::string iName) { _name = iName; } void setAge(std::string iAge) { _age = iAge; } private: std::string _name; std::string _age; }; //bool Is30(Person iPeron) //{ // if(iPeron.getAge()=="30") // { // return true; // } // return false; //} struct AgeComparator { bool operator()(Person iPerson) { if(iPerson.getAge() == _ageToCompare) { return true; } return false; } std::string _ageToCompare; }; int main() { Person aChema; aChema.setAge("30"); aChema.setName("Chema"); Person aJavi; aJavi.setAge("31"); aJavi.setName("Javi"); std::vector<Person> aVectorPerson; aVectorPerson.push_back(aChema); aVectorPerson.push_back(aJavi); AgeComparator a30Comparator; a30Comparator._ageToCompare = "31"; std::vector<Person>::iterator it = std::find_if(aVectorPerson.begin(), aVectorPerson.end(), a30Comparator); if(it != aVectorPerson.end()) { std::cout << it->getName() << std::endl; } }
run
|
edit
|
history
|
help
0
List add v2
error
dijkstra
dijkstra's algo
Visakh
PreDir
selection_sort
DP Optimization another kind
Stream11
Dar