Commit ae87e1d0 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Tweaks to member-invoke traits

Summary:
[Folly] Tweaks to member-invoke traits.
* `const`.
* No need to delegate to `invoke`.

Reviewed By: aary

Differential Revision: D8632393

fbshipit-source-id: 08ae3bc6e3ede3766ec646a5d2588996ff734538
parent aacb17f6
...@@ -186,16 +186,9 @@ struct member_invoke_proxy { ...@@ -186,16 +186,9 @@ struct member_invoke_proxy {
template <typename O, typename... Args> template <typename O, typename... Args>
static constexpr auto invoke(O&& o, Args&&... args) noexcept( static constexpr auto invoke(O&& o, Args&&... args) noexcept(
noexcept(folly::invoke( noexcept(Invoke{}(static_cast<O&&>(o), static_cast<Args&&>(args)...)))
Invoke{}, -> decltype(Invoke{}(static_cast<O&&>(o), static_cast<Args&&>(args)...)) {
static_cast<O&&>(o), return Invoke{}(static_cast<O&&>(o), static_cast<Args&&>(args)...);
static_cast<Args&&>(args)...)))
-> decltype(folly::invoke(
Invoke{},
static_cast<O&&>(o),
static_cast<Args&&>(args)...)) {
return folly::invoke(
Invoke{}, static_cast<O&&>(o), static_cast<Args&&>(args)...);
} }
}; };
...@@ -232,37 +225,37 @@ struct member_invoke_proxy { ...@@ -232,37 +225,37 @@ struct member_invoke_proxy {
* follows: * follows:
* *
* struct CanFoo { * struct CanFoo {
* int foo(Bar const&) { return 1; } * int foo(Bar&) { return 1; }
* int foo(Car&&) noexcept { return 2; } * int foo(Car&&) noexcept { return 2; }
* }; * };
* *
* using traits = foo_invoke_traits; * using traits = foo_invoke_traits;
* *
* traits::invoke(CanFoo{}, Bar{}) // 1 * traits::invoke(CanFoo{}, Car{}) // 2
* *
* traits::invoke_result<CanFoo, Bar&&> // has member * traits::invoke_result<CanFoo, Bar&> // has member
* traits::invoke_result_t<CanFoo, Bar&&> // int * traits::invoke_result_t<CanFoo, Bar&> // int
* traits::invoke_result<CanFoo, Bar&> // empty * traits::invoke_result<CanFoo, Bar&&> // empty
* traits::invoke_result_t<CanFoo, Bar&> // error * traits::invoke_result_t<CanFoo, Bar&&> // error
* *
* traits::is_invocable<CanFoo, Bar&&>::value // true * traits::is_invocable<CanFoo, Bar&>::value // true
* traits::is_invocable<CanFoo, Bar&>::value // false * traits::is_invocable<CanFoo, Bar&&>::value // false
* *
* traits::is_invocable_r<int, CanFoo, Bar&&>::value // true * traits::is_invocable_r<int, CanFoo, Bar&>::value // true
* traits::is_invocable_r<char*, CanFoo, Bar&&>::value // false * traits::is_invocable_r<char*, CanFoo, Bar&>::value // false
* *
* traits::is_nothrow_invocable<CanFoo, Bar&&>::value // false * traits::is_nothrow_invocable<CanFoo, Bar&>::value // false
* traits::is_nothrow_invocable<CanFoo, Car&&>::value // true * traits::is_nothrow_invocable<CanFoo, Car&&>::value // true
* *
* traits::is_nothrow_invocable<int, CanFoo, Bar&&>::value // false * traits::is_nothrow_invocable<int, CanFoo, Bar&>::value // false
* traits::is_nothrow_invocable<char*, CanFoo, Bar&&>::value // false * traits::is_nothrow_invocable<char*, CanFoo, Bar&>::value // false
* traits::is_nothrow_invocable<int, CanFoo, Car&&>::value // true * traits::is_nothrow_invocable<int, CanFoo, Car&&>::value // true
* traits::is_nothrow_invocable<char*, CanFoo, Car&&>::value // false * traits::is_nothrow_invocable<char*, CanFoo, Car&&>::value // false
*/ */
#define FOLLY_CREATE_MEMBER_INVOKE_TRAITS(classname, membername) \ #define FOLLY_CREATE_MEMBER_INVOKE_TRAITS(classname, membername) \
struct classname##__folly_detail_member_invoke { \ struct classname##__folly_detail_member_invoke { \
template <typename O, typename... Args> \ template <typename O, typename... Args> \
constexpr auto operator()(O&& o, Args&&... args) noexcept(noexcept( \ constexpr auto operator()(O&& o, Args&&... args) const noexcept(noexcept( \
static_cast<O&&>(o).membername(static_cast<Args&&>(args)...))) \ static_cast<O&&>(o).membername(static_cast<Args&&>(args)...))) \
-> decltype( \ -> decltype( \
static_cast<O&&>(o).membername(static_cast<Args&&>(args)...)) { \ static_cast<O&&>(o).membername(static_cast<Args&&>(args)...)) { \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment