[clang-tools-extra] [libcxx] Unifying __is_trivial_equality_predicate and __is_trivial_plus_operation into __desugars_to (PR #68642)

Louis Dionne via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 30 08:40:06 PDT 2023


================
@@ -18,8 +18,11 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-template <class _Pred, class _Lhs, class _Rhs>
-struct __is_trivial_plus_operation : false_type {};
+template <class _Operation, class _Canonical>
----------------
ldionne wrote:

I think what we want is something like this:

```
struct __equal_tag {};
struct __plus_tag {};
// etc...

template <class _CanonicalTag, class _Operation, class ..._Args>
struct __desugars_to : false_type {};


// std::equal_to and friends
template <class _Tp> struct __desugars_to<__equal_tag, equal_to<_Tp>, _Tp, _Tp> : true_type {};
template <class _Tp, class _Up> struct __desugars_to<__equal_tag, equal_to<void>, _Tp, _Up> : true_type {};
template <class _Tp, class _Up> struct __desugars_to<__equal_tag, __equal, _Tp, _Up> : true_type {};
template <class _Tp, class _Up> struct __desugars_to<__equal_tag, ranges::equal_to, _Tp, _Up> : true_type {};

// std::plus and friends
etc...
```

I originally thought that using `std::equal_to<>` as a "tag" to represent the canonical operation was a good idea, but since it doesn't exist in older standards we end up having to use `std::equal_to<void>` explicitly, and that really obfuscates the fact that it's meant to be a tag.

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


More information about the cfe-commits mailing list