[libcxx-commits] [libcxx] [libc++] Implement P2830R10: Standardized Constexpr Type Ordering (PR #216616)

Matthias Wippich via libcxx-commits libcxx-commits at lists.llvm.org
Mon Aug 17 11:46:43 PDT 2026


================
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___COMPARE_TYPE_ORDER
+#define _LIBCPP___COMPARE_TYPE_ORDER
+
+#include <__compare/ordering.h>
+#include <__config>
+
+#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 26 && __has_builtin(__builtin_type_order)
+
+// [compare.type], type ordering
+template <class _Tp, class _Up>
+struct _LIBCPP_NO_SPECIALIZATIONS type_order {
+  static constexpr strong_ordering value = __builtin_type_order(_Tp, _Up);
+  using value_type                       = strong_ordering;
+
+  _LIBCPP_HIDE_FROM_ABI constexpr operator value_type() const noexcept { return value; }
+  _LIBCPP_HIDE_FROM_ABI constexpr value_type operator()() const noexcept { return value; }
+};
+
+template <class _Tp, class _Up>
+constexpr strong_ordering type_order_v = __builtin_type_order(_Tp, _Up);
----------------
Tsche wrote:

The wording doesn't actually say `inline` here (https://eel.is/c++draft/compare.syn) and I don't think it's necessary in C++26 anymore, but libstdc++ also says `inline` here specifically ([libstdc++](https://github.com/gcc-mirror/gcc/blob/d3c381c7010c05c729febf7605855a2aaa654ede/libstdc%2B%2B-v3/libsupc%2B%2B/compare#L1283)).

Do you still prefer `inline` given the standard does not say that?

https://github.com/llvm/llvm-project/pull/216616


More information about the libcxx-commits mailing list