stdxFunctional.h Classes and Functions
A collection of simple function objects to help make stl eaiser to use. Many of these are nicer ways to create comparison predicates for use with various _if STL algorithms. You can achieve the same effect with std::bind2nd but it's ugly and harder to read. So below are two ways to do the same thing:
copy_if( iseq(lst1), back_inserter(lst2), bind2nd( less<int>(), 7 ); copy_if( iseq(lst1), back_inserter(lst2), less_than(7) );
In combination with the stdx::filter() functions this can be pretty powerful and elegant. For example if we have a collection of Person objects and we want to create a view of that list which only contains people whose occupation is Student then we could use the following:
list<Person> lst; // ... fill lst with people ... list<Person> students; copy_if( iseq(lst), back_inserter(students), filter( &Person::getOccupation, equal(Student) ) );
Compounds
- class stdx::Equal
- Function Object: Equal to predicate object.
- Function Object: Equal to predicate object.
- class stdx::NotEqual
- Function Object: Not equal to predicate object.
- Function Object: Not equal to predicate object.
- class stdx::LessThan
- Function Object: Less than predicate object.
- Function Object: Less than predicate object.
- class stdx::GreaterThan
- Function Object: Greater than predicate object.
- Function Object: Greater than predicate object.
- class stdx::LessThanOrEqual
- Function Object: Less than or equal to predicate object.
- Function Object: Less than or equal to predicate object.
- class stdx::GreaterThanOrEqual
- Function Object: Greater than or equal predicate object.
- Function Object: Greater than or equal predicate object.
Functions
Comparison Predicate Helper Functions
- equal (const T &val)
- not_equal (const T &val)
- less_than (const T &val)
- greater_than (const T &val)
- less_than_or_equal (const T &val)
- greater_than_or_equal (const T &val)