-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
The concept-constrained comparisons (std::ranges::equal_to, std::ranges::not_equal_to, std::ranges::less, std::ranges::greater, std::ranges::less_equal, std::ranges::greater_equal, std::compare_three_way) admit pairs of arguments that compare as pointers despite that they do not otherwise meet the constraints. Such arguments are recognized via the exposition-only magic macros BUILTIN-PTR-CMP ([range.cmp]/1) and BUILTIN-PTR-THREE-WAY
([comparisons.three.way]/1). These magic macros can be implemented as three compiler intrinsics:
-
__builtin_ptr_equal(T, U)which evaluates totrueifft == ufor expressionstandusuch thatdecltype((t))isTanddecltype((u))isUresolves to a builtin==operator that compares pointers. -
__builtin_ptr_less(T, U)which evaluates totrueifft < ufor expressionstandusuch thatdecltype((t))isTanddecltype((u))isUresolves to a builtin<operator that compares pointers. -
__builtin_ptr_spaceship(T, U)which evaluates totrueifft <=> ufor expressionstandusuch thatdecltype((t))isTanddecltype((u))isUresolves to a builtin<=>operator that compares pointers.
If we cannot find a way to implement the equivalent of these intrinsics in C++ - there are library implementations, but to my knowledge none that properly handle types that convert to function pointers - we need to get these intrinsics implemented in our compiler front-ends, ideally with the same set of names. (I'm not married to the names above, but they seem as good as any.)