From a95afeea0062f6292d7ed3b0eb5d0b4573b36eaf Mon Sep 17 00:00:00 2001 From: Alisdair Meredith Date: Mon, 23 Jun 2025 00:37:03 +0300 Subject: [PATCH 1/2] P2830R10 Standardized Constexpr Type Ordering Fixes #7954 Fixes cplusplus/papers#1507 --- source/support.tex | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/source/support.tex b/source/support.tex index 95d674aafb..2a87b95d74 100644 --- a/source/support.tex +++ b/source/support.tex @@ -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} @@ -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 { @@ -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 + struct type_order; + + template + constexpr strong_ordering type_order_v = type_order::value; } \end{codeblock} @@ -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 + 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}. + +\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} From 1e506de478dd953f5dfa067be6c0a836f566521a Mon Sep 17 00:00:00 2001 From: Alisdair Meredith Date: Wed, 25 Jun 2025 09:05:07 -0400 Subject: [PATCH 2/2] [compare.type] Fix argument names invoking spec macro Co-authored-by: Jonathan Wakely --- source/support.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/support.tex b/source/support.tex index 2a87b95d74..76eae23486 100644 --- a/source/support.tex +++ b/source/support.tex @@ -5709,7 +5709,7 @@ \pnum The name \tcode{type_order} denotes a \oldconcept{BinaryTypeTrait}\iref{meta.rqmts} with a base characteristic of -\tcode{integral_constant}. +\tcode{integral_constant}. \pnum \recommended