Skip to content

Commit

Permalink
[libc++] Fix expression-equivalence for mem_fn
Browse files Browse the repository at this point in the history
Previously, SFINAE constraints and exception specification propagation
were missing in the return type of libc++'s `std::mem_fn`. The
requirements on expression-equivalence (or even plain "equivalent" in
pre-C++20 specification) in [func.memfn] are actually requiring them.

This PR adds the missed stuffs.

Drive-by changes:
- removing no longer used `__invoke_return`,
- updating synopsis comments in several files, and
- merging several test files for `mem_fn` into one.
  • Loading branch information
frederick-vs-ja committed Oct 6, 2024
1 parent 4986510 commit 9c73637
Show file tree
Hide file tree
Showing 10 changed files with 745 additions and 401 deletions.
6 changes: 2 additions & 4 deletions libcxx/include/__functional/mem_fn.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ class __mem_fn : public __weak_result_type<_Tp> {

// invoke
template <class... _ArgTypes>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20

typename __invoke_return<type, _ArgTypes...>::type
operator()(_ArgTypes&&... __args) const {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __invoke_of<const _Tp&, _ArgTypes...>::type
operator()(_ArgTypes&&... __args) const _NOEXCEPT_(__nothrow_invokable<const _Tp&, _ArgTypes...>::value) {
return std::__invoke(__f_, std::forward<_ArgTypes>(__args)...);
}
};
Expand Down
5 changes: 0 additions & 5 deletions libcxx/include/__functional/weak_result_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,6 @@ struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const volatile> {
#endif
};

template <class _Tp, class... _Args>
struct __invoke_return {
typedef decltype(std::__invoke(std::declval<_Tp>(), std::declval<_Args>()...)) type;
};

_LIBCPP_END_NAMESPACE_STD

#endif // _LIBCPP___FUNCTIONAL_WEAK_RESULT_TYPE_H
2 changes: 1 addition & 1 deletion libcxx/include/functional
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const);
template <class S, class T, class A>
const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const); // deprecated in C++11, removed in C++17
template<class R, class T> constexpr unspecified mem_fn(R T::*); // constexpr in C++20
template<class R, class T> constexpr unspecified mem_fn(R T::*) noexcept; // constexpr in C++20
class bad_function_call
: public exception
Expand Down
Loading

0 comments on commit 9c73637

Please sign in to comment.