|
6831 | 6831 | \rSec2[class.spaceship]{Three-way comparison}
|
6832 | 6832 | \indextext{operator!three-way comparison!defaulted}%
|
6833 | 6833 |
|
| 6834 | +\pnum |
| 6835 | +The \defnadj{synthesized}{three-way comparison} |
| 6836 | +for comparison category type \tcode{R}\iref{cmp.categories} |
| 6837 | +of glvalues \tcode{a} and \tcode{b} of the same type |
| 6838 | +is defined as follows: |
| 6839 | + |
| 6840 | +\begin{itemize} |
| 6841 | +\item |
| 6842 | +If overload resolution for \tcode{a <=> b} |
| 6843 | +finds a usable function\iref{over.match}, |
| 6844 | +\tcode{static_cast<R>(a <=> b)}. |
| 6845 | + |
| 6846 | +\item |
| 6847 | +Otherwise, if overload resolution for \tcode{a <=> b} |
| 6848 | +finds at least one viable candidate, |
| 6849 | +the synthesized three-way comparison is not defined. |
| 6850 | + |
| 6851 | +\item |
| 6852 | +Otherwise, if \tcode{R} is \tcode{strong_ordering}, then |
| 6853 | +\begin{codeblock} |
| 6854 | +a == b ? strong_ordering::equal : |
| 6855 | +a < b ? strong_ordering::less : |
| 6856 | + strong_ordering::greater |
| 6857 | +\end{codeblock} |
| 6858 | + |
| 6859 | +\item |
| 6860 | +Otherwise, if \tcode{R} is \tcode{weak_ordering}, then |
| 6861 | +\begin{codeblock} |
| 6862 | +a == b ? weak_ordering::equal : |
| 6863 | +a < b ? weak_ordering::less : |
| 6864 | + weak_ordering::greater |
| 6865 | +\end{codeblock} |
| 6866 | + |
| 6867 | +\item |
| 6868 | +Otherwise, if \tcode{R} is \tcode{partial_ordering}, then |
| 6869 | +\begin{codeblock} |
| 6870 | +a == b ? partial_ordering::equivalent : |
| 6871 | +a < b ? partial_ordering::less : |
| 6872 | +b < a ? partial_ordering::greater : |
| 6873 | + partial_ordering::unordered |
| 6874 | +\end{codeblock} |
| 6875 | + |
| 6876 | +\item |
| 6877 | +Otherwise, if \tcode{R} is \tcode{strong_equality}, then |
| 6878 | +\begin{codeblock} |
| 6879 | +a == b ? strong_equality::equal : strong_equality::nonequal |
| 6880 | +\end{codeblock} |
| 6881 | + |
| 6882 | +\item |
| 6883 | +Otherwise, if \tcode{R} is \tcode{weak_equality}, then |
| 6884 | +\begin{codeblock} |
| 6885 | +a == b ? weak_equality::equivalent : weak_equality::nonequivalent |
| 6886 | +\end{codeblock} |
| 6887 | + |
| 6888 | +\item |
| 6889 | +Otherwise, the synthesized three-way comparison is not defined. |
| 6890 | +\end{itemize} |
| 6891 | +\begin{note} |
| 6892 | +A synthesized three-way comparison may be ill-formed |
| 6893 | +if overload resolution finds usable functions |
| 6894 | +that do not otherwise meet the requirements implied by the defined expression. |
| 6895 | +\end{note} |
| 6896 | + |
6834 | 6897 | \pnum
|
6835 | 6898 | Given an expanded list of subobjects for an object \tcode{x} of type \tcode{C},
|
6836 | 6899 | the type of the expression $\tcode{x}_i$ \tcode{<=>} $\tcode{x}_i$
|
6837 | 6900 | is denoted by $\tcode{R}_i$.
|
| 6901 | +If overload resolution as applied to $\tcode{x}_i$ \tcode{<=>} $\tcode{x}_i$ |
| 6902 | +does not find a usable function, |
| 6903 | +then $\tcode{R}_i$ is \tcode{void}. |
6838 | 6904 | If the declared return type
|
6839 | 6905 | of a defaulted three-way comparison operator function
|
6840 | 6906 | is \tcode{auto},
|
6841 | 6907 | then the return type is deduced as
|
6842 | 6908 | the common comparison type (see below) of
|
6843 | 6909 | $\tcode{R}_0$, $\tcode{R}_1$, $\dotsc$, $\tcode{R}_{n-1}$.
|
6844 |
| -\begin{note} |
6845 |
| -Otherwise, |
6846 |
| -the program will be ill-formed |
6847 |
| -if the expression $\tcode{x}_i$ \tcode{<=>} $\tcode{x}_i$ |
6848 |
| -is not implicitly convertible to the declared return type for any $i$. |
6849 |
| -\end{note} |
6850 | 6910 | If the return type is deduced as \tcode{void},
|
6851 | 6911 | the operator function is defined as deleted.
|
| 6912 | +If the declared return type of |
| 6913 | +a defaulted three-way comparison operator function |
| 6914 | +is \tcode{R} |
| 6915 | +and the synthesized three-way comparison |
| 6916 | +for comparison category type \tcode{R} |
| 6917 | +between any objects $\tcode{x}_i$ and $\tcode{x}_i$ |
| 6918 | +is not defined or would be ill-formed, |
| 6919 | +the operator function is defined as deleted. |
6852 | 6920 |
|
6853 | 6921 | \pnum
|
6854 | 6922 | The return value \tcode{V} of type \tcode{R}
|
|
6858 | 6926 | $\tcode{x}_i$ and $\tcode{y}_i$
|
6859 | 6927 | in the expanded lists of subobjects for \tcode{x} and \tcode{y}
|
6860 | 6928 | (in increasing index order)
|
6861 |
| -until the first index $i$ |
6862 |
| -where $\tcode{x}_i$ \tcode{<=>} $\tcode{y}_i$ |
| 6929 | +until the first index $i$ where |
| 6930 | +the synthesized three-way comparison for comparison category type \tcode{R} |
| 6931 | +between $\tcode{x}_i$ and $\tcode{y}_i$ |
6863 | 6932 | yields a result value $\tcode{v}_i$ where $\tcode{v}_i \mathrel{\tcode{!=}} 0$,
|
6864 | 6933 | contextually converted to \tcode{bool}, yields \tcode{true};
|
6865 | 6934 | \tcode{V} is $\tcode{v}_i$ converted to \tcode{R}.
|
|
0 commit comments