cppannotations/yo/stl/relational.yo
2010-02-28 16:34:35 +00:00

39 lines
2.1 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:
itemization(
itht(equal_to)(equal_to>): this object's tt(operator()) member calls
ti(operator==),
passing the latter operator its two parameter values
and returning the latter operator's return value.
itht(not_equal_to)(not_equal_to<>): this object's tt(operator()) member
calls ti(operator!=), passing the latter operator its two parameter values and
returning the latter operator's return value.
itht(greater)(greater<>): this object's tt(operator()) member calls
ti(operator>), passing the latter operator its two parameter values
and returning the latter operator's return value.
itht(greater_equal)(greater_equal<>): this object's tt(operator()) member
calls ti(operator>=), passing the latter operator its two parameter values and
returning the latter operator's return value.
itht(less)(less<>): this object's tt(operator()) member calls
ti(operator<), passing the latter operator its two parameter values and
returning the latter operator's return value.
itht(less_equal)(less_equal<>): this object's tt(operator()) member calls
ti(operator<=), passing the latter operator its two parameter values
and returning the latter operator's return value.
)
An example using the relational function objects in combination with
ti(sort) is:
verbinclude(stl/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.