Skip to content

P2830R10 Standardized Constexpr Type Ordering #7992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions source/support.tex
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@
// also in \libheader{utility}, \libheader{tuple}, \libheader{map}, \libheader{unordered_map}
#define @\defnlibxname{cpp_lib_tuples_by_type}@ 201304L // freestanding, also in \libheader{utility}, \libheader{tuple}
#define @\defnlibxname{cpp_lib_type_identity}@ 201806L // freestanding, also in \libheader{type_traits}
#define @\defnlibxname{cpp_lib_type_order}@ 202506L // also in \libheader{compare}
#define @\defnlibxname{cpp_lib_type_trait_variable_templates}@ 201510L // freestanding, also in \libheader{type_traits}
#define @\defnlibxname{cpp_lib_uncaught_exceptions}@ 201411L // freestanding, also in \libheader{exception}
#define @\defnlibxname{cpp_lib_unordered_map_try_emplace}@ 201411L // also in \libheader{unordered_map}
Expand Down Expand Up @@ -4765,6 +4766,7 @@
\indexlibraryglobal{is_geq}%
\indexlibraryglobal{is_gteq}%
\indexlibraryglobal{common_comparison_category_t}%
\indexlibraryglobal{type_order_v}%
\begin{codeblock}
// all freestanding
namespace std {
Expand Down Expand Up @@ -4813,6 +4815,13 @@
inline constexpr @\unspec@ compare_weak_order_fallback = @\unspec@;
inline constexpr @\unspec@ compare_partial_order_fallback = @\unspec@;
}

// \ref{compare.type}, type ordering
template<class T, class U>
struct type_order;

template<class T, class U>
constexpr strong_ordering type_order_v = type_order<T, U>::value;
}
\end{codeblock}

Expand Down Expand Up @@ -5668,6 +5677,45 @@
of a template instantiation.
\end{note}

\rSec2[compare.type]{Type Ordering}

\pnum
There is an \impldef{total ordering of all types} total ordering of all types.
For any (possibly incomplete) types \tcode{X} and \tcode{Y},
the expression \tcode{\exposid{TYPE-ORDER}(X, Y)} is a constant expression\iref{expr.const}
of type \tcode{strong_ordering}\iref{cmp.strongord}.
Its value is \tcode{strong_ordering::less} if \tcode{X} precedes \tcode{Y}
in this implementation-defined total order,
\tcode{strong_ordering::greater} if \tcode{Y} precedes \tcode{X}, and
\tcode{strong_ordering::equal} if they are the same type.
\begin{note}
\tcode{int}, \tcode{const int} and \tcode{int\&} are different types.
\end{note}
\begin{note}
This ordering need not be consistent with the one induced by \tcode{type_info::before}.
\end{note}
\begin{note}
The ordering of TU-local types from different translation units is not observable,
because the necessary specialization of \tcode{type_order} is impossible to name.
\end{note}

\indexlibraryglobal{type_order}%
\begin{itemdecl}
template<class T, class U>
struct type_order;
\end{itemdecl}

\begin{itemdescr}
\pnum
The name \tcode{type_order} denotes a \oldconcept{BinaryTypeTrait}\iref{meta.rqmts}
with a base characteristic of
\tcode{integral_constant<strong_ordering, \exposid{TYPE-ORDER}(T, U)>}.

\pnum
\recommended
The order should be lexicographical on parameter-type-lists and template argument lists.
\end{itemdescr}

\rSec1[support.coroutine]{Coroutines}

\rSec2[support.coroutine.general]{General}
Expand Down
Loading