cppannotations/yo/stl/relational.yo
Frank B. Brokken 4d48524f9e WIP
git-svn-id: https://cppannotations.svn.sourceforge.net/svnroot/cppannotations/trunk@498 f6dd340e-d3f9-0310-b409-bdd246841980
2010-12-20 14:40:35 +00:00

31 lines
1.6 KiB
Text

The relational operators are called by the
hi(function object: relational)hi(relational function object) relational
function objects. All standard relational operators are supported: tt(==, !=,
>, >=, <) and tt(<=).
The STL supports the following set of relational function objects. The
function call operator (tt(operator())) of these function objects calls the
matching relational operator for the objects that are passed to the function
call operator, returning that relational operator's return value. The
relational operator that is actually called is mentioned below:
itemization(
itht(equal_to)(equal_to<>): calls ti(operator==);
itht(not_equal_to)(not_equal_to<>): calls ti(operator!=);
itht(greater)(greater<>): calls ti(operator>);
itht(greater_equal)(greater_equal<>): calls ti(operator>=);
itht(less)(less<>): this object's tt(operator()) member calls
ti(operator<);
itht(less_equal)(less_equal<>): calls ti(operator<=).
)
An example using the relational function objects in combination with
ti(sort) is:
verbinclude(examples/sort.cc)
The example illustrates how strings may be alphabetically and reversed
alphabetically sorted. By passing tt(greater_equal<string>) the strings are
sorted in em(decreasing) order (the first word will be the 'greatest'), by
passing tt(less<string>) the strings are sorted in em(increasing) order (the
first word will be the 'smallest').
Note that tt(argv) contains tt(char *) values, and that the relational
function object expects a tt(string). The promotion from tt(char const *) to
tt(string) is silently performed.