[libcxx-commits] [libcxx] 48c805b - [libcxx] replaces SFINAE with requires-expressions in `bind_front` and `bind_back` (#68249)

via libcxx-commits libcxx-commits at lists.llvm.org
Thu Oct 5 10:32:12 PDT 2023


Author: Christopher Di Bella
Date: 2023-10-05T10:32:08-07:00
New Revision: 48c805bafdfd6b2ece12d809c67b887b39bd739f

URL: https://github.com/llvm/llvm-project/commit/48c805bafdfd6b2ece12d809c67b887b39bd739f
DIFF: https://github.com/llvm/llvm-project/commit/48c805bafdfd6b2ece12d809c67b887b39bd739f.diff

LOG: [libcxx] replaces SFINAE with requires-expressions in `bind_front` and `bind_back` (#68249)

The diagnostics for `enable_if_t` are extremely opaque:

```
error: no matching function for call to 'bind_front'
note: candidate template ignored: requirement 'integral_constant<bool, false>::value' was not satisfied
```

Using requires-expressions gives us a little more context:

```
error: no matching function for call to 'bind_front'
note: candidate template ignored: constraints not satisfied
note: because 'is_constructible_v<decay_t<T &>, T &>' evaluated to false
```

Pull request: #68249

Added: 
    

Modified: 
    libcxx/include/__functional/bind_back.h
    libcxx/include/__functional/bind_front.h

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__functional/bind_back.h b/libcxx/include/__functional/bind_back.h
index 71dc63c86bdbeed..0dd2befb5240946 100644
--- a/libcxx/include/__functional/bind_back.h
+++ b/libcxx/include/__functional/bind_back.h
@@ -43,14 +43,9 @@ struct __bind_back_t : __perfect_forward<__bind_back_op<tuple_size_v<_BoundArgs>
     using __perfect_forward<__bind_back_op<tuple_size_v<_BoundArgs>>, _Fn, _BoundArgs>::__perfect_forward;
 };
 
-template <class _Fn, class ..._Args, class = enable_if_t<
-    _And<
-        is_constructible<decay_t<_Fn>, _Fn>,
-        is_move_constructible<decay_t<_Fn>>,
-        is_constructible<decay_t<_Args>, _Args>...,
-        is_move_constructible<decay_t<_Args>>...
-    >::value
->>
+template <class _Fn, class... _Args>
+  requires is_constructible_v<decay_t<_Fn>, _Fn> && is_move_constructible_v<decay_t<_Fn>> &&
+           (is_constructible_v<decay_t<_Args>, _Args> && ...) && (is_move_constructible_v<decay_t<_Args>> && ...)
 _LIBCPP_HIDE_FROM_ABI
 constexpr auto __bind_back(_Fn&& __f, _Args&&... __args)
     noexcept(noexcept(__bind_back_t<decay_t<_Fn>, tuple<decay_t<_Args>...>>(_VSTD::forward<_Fn>(__f), _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...))))

diff  --git a/libcxx/include/__functional/bind_front.h b/libcxx/include/__functional/bind_front.h
index 72bb66480959626..7ccd6e563b6e19e 100644
--- a/libcxx/include/__functional/bind_front.h
+++ b/libcxx/include/__functional/bind_front.h
@@ -42,14 +42,9 @@ struct __bind_front_t : __perfect_forward<__bind_front_op, _Fn, _BoundArgs...> {
     using __perfect_forward<__bind_front_op, _Fn, _BoundArgs...>::__perfect_forward;
 };
 
-template <class _Fn, class... _Args, class = enable_if_t<
-    _And<
-        is_constructible<decay_t<_Fn>, _Fn>,
-        is_move_constructible<decay_t<_Fn>>,
-        is_constructible<decay_t<_Args>, _Args>...,
-        is_move_constructible<decay_t<_Args>>...
-    >::value
->>
+template <class _Fn, class... _Args>
+  requires is_constructible_v<decay_t<_Fn>, _Fn> && is_move_constructible_v<decay_t<_Fn>> &&
+           (is_constructible_v<decay_t<_Args>, _Args> && ...) && (is_move_constructible_v<decay_t<_Args>> && ...)
 _LIBCPP_HIDE_FROM_ABI
 constexpr auto bind_front(_Fn&& __f, _Args&&... __args) {
     return __bind_front_t<decay_t<_Fn>, decay_t<_Args>...>(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...);


        


More information about the libcxx-commits mailing list