|
BDE 4.14.0 Production release
|
Provide implementation utilities for operator<=>.
This component provides a namespace class, bslalg::SynthThreeWayUtil, that contains an implementation of the Standard exposition-only entities (see [expos.only.entity] in the C++20 Standard): synth-three-way (bslalg::SynthThreeWayUtil::compare) and synth-three-way-result (bslalg::SynthThreeWayUtil::Result).
bslalg::SynthThreeWayUtil::compare is a callable object with the following effective signature:
It returns the result of t1 <=> t2 expression if this expression is valid. Otherwise, if t1 < t2 and t2 < t1 expressions are well-formed and return boolean-testable results, operator< is used to emulate operator<=>. Otherwise this function is not defined and does not participate in overload resolution.
As shown above, bslalg::SynthThreeWayUtil::Result<T1, T2> is a type returned by bslalg::SynthThreeWayUtil::compare<T1, T2>.
This section illustrates intended use of this component.
In the following example we use bslalg::SynthThreeWayUtil to implement the three-way comparison operator (<=>) for a list container (whose details have been elided):
Now the <, >, <= and >= operators are automatically defined for the container: