Skip to content

Commit

Permalink
Merge pull request #476 from eugeneko/ek/ref
Browse files Browse the repository at this point in the history
Use invoke_result instead of result_of in reference_wrapper.
  • Loading branch information
grojo-ea authored Jul 26, 2022
2 parents 46b5321 + 00216eb commit 5eb9b1e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
7 changes: 4 additions & 3 deletions include/EASTL/internal/functional_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ namespace eastl

template <typename R, typename F, typename... Args>
struct is_invocable_r_impl<R, F, void_t<typename invoke_result<F, Args...>::type>, Args...>
: public is_convertible<typename invoke_result<F, Args...>::type, R> {};
: public disjunction<is_convertible<typename invoke_result<F, Args...>::type, R>,
is_same<typename remove_cv<R>::type, void>> {};

template <typename R, typename F, typename... Args>
struct is_invocable_r : public is_invocable_r_impl<R, F, void, Args...> {};
Expand Down Expand Up @@ -232,7 +233,7 @@ namespace eastl
T& get() const EA_NOEXCEPT;

template <typename... ArgTypes>
typename eastl::result_of<T&(ArgTypes&&...)>::type operator() (ArgTypes&&...) const;
typename eastl::invoke_result<T&, ArgTypes...>::type operator() (ArgTypes&&...) const;

private:
T* val;
Expand Down Expand Up @@ -269,7 +270,7 @@ namespace eastl

template <typename T>
template <typename... ArgTypes>
typename eastl::result_of<T&(ArgTypes&&...)>::type reference_wrapper<T>::operator() (ArgTypes&&... args) const
typename eastl::invoke_result<T&, ArgTypes...>::type reference_wrapper<T>::operator() (ArgTypes&&... args) const
{
return eastl::invoke(*val, eastl::forward<ArgTypes>(args)...);
}
Expand Down
34 changes: 34 additions & 0 deletions test/source/TestFunctional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1491,5 +1491,39 @@ struct TestInvokeResult
};

template struct eastl::invoke_result<decltype(&TestInvokeResult::f), TestInvokeResult, void>;

static_assert(!eastl::is_invocable<decltype(&TestInvokeResult::f), TestInvokeResult, void>::value, "incorrect value for is_invocable");
static_assert(!eastl::is_invocable<decltype(&TestInvokeResult::f), TestInvokeResult, int, int>::value, "incorrect value for is_invocable");
static_assert(eastl::is_invocable<decltype(&TestInvokeResult::f), TestInvokeResult, int>::value, "incorrect value for is_invocable");

static_assert(!eastl::is_invocable_r<int, decltype(&TestInvokeResult::f), TestInvokeResult, void>::value, "incorrect value for is_invocable_r");
static_assert(!eastl::is_invocable_r<void, decltype(&TestInvokeResult::f), TestInvokeResult, int, int>::value, "incorrect value for is_invocable_r");
static_assert(eastl::is_invocable_r<void, decltype(&TestInvokeResult::f), TestInvokeResult, int>::value, "incorrect value for is_invocable_r");
static_assert(eastl::is_invocable_r<int, decltype(&TestInvokeResult::f), TestInvokeResult, int>::value, "incorrect value for is_invocable_r");

struct TestCallableInvokeResult
{
int operator()(int i) {return i;}
};

template struct eastl::invoke_result<TestCallableInvokeResult, void>;

static_assert(!eastl::is_invocable<TestCallableInvokeResult, void>::value, "incorrect value for is_invocable");
static_assert(!eastl::is_invocable<TestCallableInvokeResult, int, int>::value, "incorrect value for is_invocable");
static_assert(eastl::is_invocable<TestCallableInvokeResult, int>::value, "incorrect value for is_invocable");

static_assert(!eastl::is_invocable_r<int, TestCallableInvokeResult, void>::value, "incorrect value for is_invocable_r");
static_assert(!eastl::is_invocable_r<void, TestCallableInvokeResult, int, int>::value, "incorrect value for is_invocable_r");
static_assert(eastl::is_invocable_r<void, TestCallableInvokeResult, int>::value, "incorrect value for is_invocable_r");
static_assert(eastl::is_invocable_r<int, TestCallableInvokeResult, int>::value, "incorrect value for is_invocable_r");

typedef decltype(eastl::ref(eastl::declval<TestCallableInvokeResult&>())) TestCallableRefInvokeResult;

static_assert(!eastl::is_invocable<TestCallableRefInvokeResult, void>::value, "incorrect value for is_invocable");
static_assert(!eastl::is_invocable<TestCallableRefInvokeResult, int, int>::value, "incorrect value for is_invocable");
static_assert(eastl::is_invocable<TestCallableRefInvokeResult, int>::value, "incorrect value for is_invocable");

static_assert(!eastl::is_invocable_r<int, TestCallableRefInvokeResult, void>::value, "incorrect value for is_invocable_r");
static_assert(!eastl::is_invocable_r<void, TestCallableRefInvokeResult, int, int>::value, "incorrect value for is_invocable_r");
static_assert(eastl::is_invocable_r<void, TestCallableRefInvokeResult, int>::value, "incorrect value for is_invocable_r");
static_assert(eastl::is_invocable_r<int, TestCallableRefInvokeResult, int>::value, "incorrect value for is_invocable_r");

0 comments on commit 5eb9b1e

Please sign in to comment.