[libcxx-commits] [libcxx] [RFC][libc++] Fixes valarray proxy type operations. (PR #76528)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jan 16 10:06:42 PST 2024


================
@@ -916,6 +947,21 @@ template <class _Tp, size_t _Size>
 valarray(const _Tp (&)[_Size], size_t) -> valarray<_Tp>;
 #endif
 
+template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
+_LIBCPP_HIDE_FROM_ABI typename _Expr::value_type __get(const _Expr& __v, size_t __i, true_type) {
+  return __v.__get(__i);
+}
+
+template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
+_LIBCPP_HIDE_FROM_ABI typename _Expr::value_type __get(const _Expr& __v, size_t __i, false_type) {
+  return __v[__i];
+}
+
+template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
+_LIBCPP_HIDE_FROM_ABI typename _Expr::value_type __get(const _Expr& __v, size_t __i) {
+  return std::__get(__v, __i, __index_use_member_get<_Expr>()) ;
+}
----------------
ldionne wrote:

Simplification suggestion:

```suggestion
template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value && __index_use_member_get<_Expr>(), int> = 0>
_LIBCPP_HIDE_FROM_ABI typename _Expr::value_type __get(const _Expr& __v, size_t __i) {
  return __v.__get(__i);
}

template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value && !__index_use_member_get<_Expr>(), int> = 0>
_LIBCPP_HIDE_FROM_ABI typename _Expr::value_type __get(const _Expr& __v, size_t __i) {
  return __v[__i];
}
```


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


More information about the libcxx-commits mailing list