[libcxx-commits] [PATCH] D107199: [libc++] Refactor __perfect_forward, bind_front and not_fn
Arthur O'Dwyer via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Aug 9 07:13:27 PDT 2021
Quuxplusone added inline comments.
================
Comment at: libcxx/include/__functional/perfect_forward.h:42
- template<class... _Args>
- _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) &
- noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
- -> decltype( _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...))
- {return _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...);}
-
- template<class... _Args>
- _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const&
- noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
- -> decltype( _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...))
- {return _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...);}
-
- template<class... _Args>
- _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) &&
- noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
- _VSTD::forward<_Args>(__args)...)))
- -> decltype( _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
- _VSTD::forward<_Args>(__args)...))
- {return _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
- _VSTD::forward<_Args>(__args)...);}
-
- template<class... _Args>
- _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const&&
- noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
- _VSTD::forward<_Args>(__args)...)))
- -> decltype( _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
- _VSTD::forward<_Args>(__args)...))
- {return _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
- _VSTD::forward<_Args>(__args)...);}
-
- template<class _Fn = typename tuple_element<0, tuple<_Bound...>>::type,
- class = _EnableIf<is_copy_constructible_v<_Fn>>>
- constexpr __perfect_forward_impl(__perfect_forward_impl const& __other)
- : __bound_(__other.__bound_) {}
-
- template<class _Fn = typename tuple_element<0, tuple<_Bound...>>::type,
- class = _EnableIf<is_move_constructible_v<_Fn>>>
- constexpr __perfect_forward_impl(__perfect_forward_impl && __other)
- : __bound_(_VSTD::move(__other.__bound_)) {}
-
- template<class... _BoundArgs>
- explicit constexpr __perfect_forward_impl(_BoundArgs&&... __bound) :
- __bound_(_VSTD::forward<_BoundArgs>(__bound)...) { }
+ template<class _Tuple, class ..._Args, class = decltype(_Op::__call(_VSTD::get<_Idx>(declval<_Tuple>())..., declval<_Args>()...))>
+ static auto __can_call_impl(int) -> true_type;
----------------
ldionne wrote:
> zoecarver wrote:
> > zoecarver wrote:
> > > This makes me wonder if we should replace `__call` with `operator()` and then we can just use `is_invocable` here. I guess we could really do that anyway, though.
> > Concepts would make a lot of this a lot easier :(
> Yeah, I think it does work actually. Please take a look at my new implementation, I think it's much simpler now.
Per my "When Should You Give Two Things the Same Name?", you know I'm leery of giving this detail the same name as the ordinary call operator. Do we ever publicly inherit from `__perfect_forward_impl`, or do anything else where the user-programmer might observe that `foo(1,2,3)` works when it shouldn't?
(Whereas the user-programmer is not allowed to observe that `foo.__call(1,2,3)` works, because `__call` is a reserved name.)
However, I'm not asking for it to be changed back //unless// someone (not me) comes up with the actual concrete example that proves why the name `operator()` can't be used. I'm just betting that such an example exists.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D107199/new/
https://reviews.llvm.org/D107199
More information about the libcxx-commits
mailing list