[libcxx-commits] [libcxx] [libc++] Fix ambiguity due to non-uglified member typedefs (PR #121664)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jan 9 03:10:31 PST 2025


================
@@ -41,6 +42,12 @@ struct __has_storage_type {
   static const bool value = false;
 };
 
+template <typename _Cp>
+struct __size_difference_type_traits {
+  using difference_type = typename _Cp::difference_type;
+  using size_type       = typename _Cp::size_type;
+};
----------------
frederick-vs-ja wrote:

I guess we can use SFINAE tricks - if `_Cp` has both `difference_type` & `size_type` then use them, otherwise fall back to `ptrdiff_t` & `size_t`. Then `__size_difference_type_traits` can be only used within this header.

```suggestion
template <class, class = void>
struct __size_difference_type_traits {
  using difference_type = ptrdiff_t;
  using size_type       = size_t;
};

template <class _Cp>
struct __size_difference_type_traits<_Cp, __void_t<typename _Cp::difference_type, typename _Cp::size_type> > {
  using difference_type = typename _Cp::difference_type;
  using size_type       = typename _Cp::size_type;
};
```
 (`<__type_traits/void_t.h>` should be included if do so.)

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


More information about the libcxx-commits mailing list