Skip to content

Commit

Permalink
Merge pull request #2672 from STEllAR-GROUP/invoke
Browse files Browse the repository at this point in the history
C++17 invoke forms
  • Loading branch information
hkaiser committed Jun 5, 2017
2 parents 2aaf99f + 6693534 commit 67870fc
Show file tree
Hide file tree
Showing 66 changed files with 402 additions and 369 deletions.
8 changes: 4 additions & 4 deletions hpx/apply.hpp
Expand Up @@ -42,7 +42,7 @@ namespace hpx { namespace detail
template <typename F, typename ...Ts>
HPX_FORCEINLINE static
typename std::enable_if<
traits::detail::is_deferred_callable<F(Ts&&...)>::value,
traits::detail::is_deferred_invocable<F, Ts...>::value,
bool
>::type
call(F&& f, Ts&&... ts)
Expand All @@ -65,7 +65,7 @@ namespace hpx { namespace detail
template <typename F, typename ...Ts>
HPX_FORCEINLINE static
typename std::enable_if<
traits::detail::is_deferred_callable<F(Ts&&...)>::value,
traits::detail::is_deferred_invocable<F, Ts...>::value,
bool
>::type
call(Executor& sched, F&& f, Ts&&... ts)
Expand All @@ -88,7 +88,7 @@ namespace hpx { namespace detail
template <typename F, typename ...Ts>
HPX_FORCEINLINE static
typename std::enable_if<
traits::detail::is_deferred_callable<F(Ts&&...)>::value,
traits::detail::is_deferred_invocable<F, Ts...>::value,
bool
>::type
call(Executor& exec, F&& f, Ts&&... ts)
Expand All @@ -111,7 +111,7 @@ namespace hpx { namespace detail
template <typename F, typename ...Ts>
HPX_FORCEINLINE static
typename std::enable_if<
traits::detail::is_deferred_callable<F(Ts&&...)>::value,
traits::detail::is_deferred_invocable<F, Ts...>::value,
bool
>::type
call(Executor& exec, F && f, Ts &&... ts)
Expand Down
90 changes: 36 additions & 54 deletions hpx/async.hpp
Expand Up @@ -17,7 +17,6 @@
#include <hpx/traits/is_launch_policy.hpp>
#include <hpx/util/bind_action.hpp>
#include <hpx/util/deferred_call.hpp>
#include <hpx/util/lazy_enable_if.hpp>

#if defined(HPX_HAVE_EXECUTOR_COMPATIBILITY)
#include <hpx/traits/is_executor_v1.hpp>
Expand All @@ -31,33 +30,17 @@

namespace hpx { namespace detail
{
// Defer the evaluation of result_of during the SFINAE checks below
#if defined(__clang__)
template <typename F, typename Result =
typename util::detail::deferred_result_of<F>::type>
struct create_future
{
typedef lcos::future<Result> type;
};
#else
template <typename F, typename ResultOf = util::detail::deferred_result_of<F> >
struct create_future
{
typedef lcos::future<typename ResultOf::type> type;
};
#endif

template <typename F>
HPX_FORCEINLINE
typename util::lazy_enable_if<
typename std::enable_if<
std::is_reference<
typename util::detail::deferred_result_of<F&&()>::type
typename util::detail::invoke_deferred_result<F>::type
>::value
, detail::create_future<F&&()>
, lcos::future<typename util::detail::invoke_deferred_result<F>::type>
>::type
call_sync(F&& f, std::false_type)
{
typedef typename util::detail::deferred_result_of<F&&()>::type result_type;
typedef typename util::detail::invoke_deferred_result<F>::type result_type;
try
{
return lcos::make_ready_future(std::ref(f()));
Expand All @@ -69,15 +52,15 @@ namespace hpx { namespace detail

template <typename F>
HPX_FORCEINLINE
typename util::lazy_enable_if<
typename std::enable_if<
!std::is_reference<
typename util::detail::deferred_result_of<F&&()>::type
typename util::detail::invoke_deferred_result<F>::type
>::value
, detail::create_future<F()>
, lcos::future<typename util::detail::invoke_deferred_result<F>::type>
>::type
call_sync(F&& f, std::false_type) //-V659
{
typedef typename util::detail::deferred_result_of<F()>::type result_type;
typedef typename util::detail::invoke_deferred_result<F>::type result_type;
try
{
return lcos::make_ready_future(f());
Expand All @@ -88,7 +71,8 @@ namespace hpx { namespace detail
}

template <typename F>
HPX_FORCEINLINE typename detail::create_future<F()>::type
HPX_FORCEINLINE
lcos::future<typename util::detail::invoke_deferred_result<F>::type>
call_sync(F&& f, std::true_type)
{
try
Expand All @@ -110,16 +94,15 @@ namespace hpx { namespace detail
template <typename F, typename ...Ts>
HPX_FORCEINLINE static
typename std::enable_if<
traits::detail::is_deferred_callable<F&&(Ts&&...)>::value,
traits::detail::is_deferred_invocable<F, Ts...>::value,
hpx::future<
typename util::detail::deferred_result_of<F&&(Ts&&...)>::type
typename util::detail::invoke_deferred_result<F, Ts...>::type
>
>::type
call(launch policy, F && f, Ts&&... ts)
{
typedef typename util::detail::deferred_result_of<
F(Ts&&...)
>::type result_type;
typedef typename util::detail::invoke_deferred_result<F, Ts...>::type
result_type;

if (policy == launch::sync)
{
Expand All @@ -145,14 +128,14 @@ namespace hpx { namespace detail
template <typename F, typename ...Ts>
HPX_FORCEINLINE static
typename std::enable_if<
traits::detail::is_deferred_callable<F&&(Ts&&...)>::value,
traits::detail::is_deferred_invocable<F, Ts...>::value,
hpx::future<
typename util::detail::deferred_result_of<F&&(Ts&&...)>::type
typename util::detail::invoke_deferred_result<F, Ts...>::type
>
>::type
call(hpx::detail::sync_policy, F && f, Ts&&... ts)
{
typedef typename util::detail::deferred_result_of<F(Ts&&...)>::type
typedef typename util::detail::invoke_deferred_result<F, Ts...>::type
result_type;

return detail::call_sync(
Expand All @@ -163,14 +146,14 @@ namespace hpx { namespace detail
template <typename F, typename ...Ts>
HPX_FORCEINLINE static
typename std::enable_if<
traits::detail::is_deferred_callable<F&&(Ts&&...)>::value,
traits::detail::is_deferred_invocable<F, Ts...>::value,
hpx::future<
typename util::detail::deferred_result_of<F&&(Ts&&...)>::type
typename util::detail::invoke_deferred_result<F, Ts...>::type
>
>::type
call(hpx::detail::async_policy policy, F && f, Ts&&... ts)
{
typedef typename util::detail::deferred_result_of<F(Ts&&...)>::type
typedef typename util::detail::invoke_deferred_result<F, Ts...>::type
result_type;

lcos::local::futures_factory<result_type()> p(
Expand All @@ -183,14 +166,14 @@ namespace hpx { namespace detail
template <typename F, typename ...Ts>
HPX_FORCEINLINE static
typename std::enable_if<
traits::detail::is_deferred_callable<F&&(Ts&&...)>::value,
traits::detail::is_deferred_invocable<F, Ts...>::value,
hpx::future<
typename util::detail::deferred_result_of<F&&(Ts&&...)>::type
typename util::detail::invoke_deferred_result<F, Ts...>::type
>
>::type
call(hpx::detail::fork_policy policy, F && f, Ts&&... ts)
{
typedef typename util::detail::deferred_result_of<F(Ts&&...)>::type
typedef typename util::detail::invoke_deferred_result<F, Ts...>::type
result_type;

lcos::local::futures_factory<result_type()> p(
Expand All @@ -205,14 +188,14 @@ namespace hpx { namespace detail
template <typename F, typename ...Ts>
HPX_FORCEINLINE static
typename std::enable_if<
traits::detail::is_deferred_callable<F&&(Ts&&...)>::value,
traits::detail::is_deferred_invocable<F, Ts...>::value,
hpx::future<
typename util::detail::deferred_result_of<F&&(Ts&&...)>::type
typename util::detail::invoke_deferred_result<F, Ts...>::type
>
>::type
call(hpx::detail::deferred_policy, F && f, Ts&&... ts)
{
typedef typename util::detail::deferred_result_of<F(Ts&&...)>::type
typedef typename util::detail::invoke_deferred_result<F, Ts...>::type
result_type;

lcos::local::futures_factory<result_type()> p(
Expand All @@ -230,9 +213,9 @@ namespace hpx { namespace detail
template <typename F, typename ...Ts>
HPX_FORCEINLINE static
typename std::enable_if<
traits::detail::is_deferred_callable<F&&(Ts&&...)>::value,
traits::detail::is_deferred_invocable<F, Ts...>::value,
hpx::future<
typename util::detail::deferred_result_of<F&&(Ts&&...)>::type
typename util::detail::invoke_deferred_result<F, Ts...>::type
>
>::type
call(F&& f, Ts&&... ts)
Expand All @@ -252,16 +235,15 @@ namespace hpx { namespace detail
template <typename Executor_, typename F, typename ...Ts>
HPX_FORCEINLINE static
typename std::enable_if<
traits::detail::is_deferred_callable<F&&(Ts&&...)>::value,
traits::detail::is_deferred_invocable<F, Ts...>::value,
hpx::future<
typename util::detail::deferred_result_of<F&&(Ts&&...)>::type
typename util::detail::invoke_deferred_result<F, Ts...>::type
>
>::type
call(Executor_ && sched, F&& f, Ts&&... ts)
{
typedef typename util::detail::deferred_result_of<
F(Ts&&...)
>::type result_type;
typedef typename util::detail::invoke_deferred_result<F, Ts...>::type
result_type;

lcos::local::futures_factory<result_type()> p(
std::forward<Executor_>(sched),
Expand All @@ -282,9 +264,9 @@ namespace hpx { namespace detail
template <typename F, typename ...Ts>
HPX_FORCEINLINE static
typename std::enable_if<
traits::detail::is_deferred_callable<F&&(Ts&&...)>::value,
traits::detail::is_deferred_invocable<F, Ts...>::value,
hpx::future<
typename util::detail::deferred_result_of<F&&(Ts&&...)>::type
typename util::detail::invoke_deferred_result<F, Ts...>::type
>
>::type
call(Executor& exec, F&& f, Ts&&... ts)
Expand All @@ -306,9 +288,9 @@ namespace hpx { namespace detail
template <typename Executor_, typename F, typename ...Ts>
HPX_FORCEINLINE static
typename std::enable_if<
traits::detail::is_deferred_callable<F&&(Ts&&...)>::value,
traits::detail::is_deferred_invocable<F, Ts...>::value,
hpx::future<
typename util::detail::deferred_result_of<F&&(Ts&&...)>::type
typename util::detail::invoke_deferred_result<F, Ts...>::type
>
>::type
call(Executor_ && exec, F && f, Ts &&... ts)
Expand Down
4 changes: 2 additions & 2 deletions hpx/compute/host/block_executor.hpp
Expand Up @@ -116,7 +116,7 @@ namespace hpx { namespace compute { namespace host

template <typename F, typename ... Ts>
hpx::future<
typename hpx::util::detail::deferred_result_of<F(Ts&&...)>::type>
typename hpx::util::detail::invoke_deferred_result<F, Ts...>::type>
async_execute(F && f, Ts &&... ts)
{
std::size_t current = ++current_ % executors_.size();
Expand All @@ -125,7 +125,7 @@ namespace hpx { namespace compute { namespace host
}

template <typename F, typename ... Ts>
typename hpx::util::detail::deferred_result_of<F(Ts&&...)>::type
typename hpx::util::detail::invoke_deferred_result<F, Ts...>::type
sync_execute(F && f, Ts &&... ts)
{
std::size_t current = ++current_ % executors_.size();
Expand Down
4 changes: 2 additions & 2 deletions hpx/lcos/async_continue_fwd.hpp
Expand Up @@ -29,12 +29,12 @@ namespace hpx
template <typename Action, typename Cont>
struct result_of_async_continue
: traits::action_remote_result<
typename util::result_of<typename util::decay<Cont>::type(
typename util::invoke_result<typename util::decay<Cont>::type,
naming::id_type,
typename hpx::traits::extract_action<
Action
>::remote_result_type
)>::type
>::type
>
{};

Expand Down
2 changes: 1 addition & 1 deletion hpx/lcos/dataflow.hpp
Expand Up @@ -111,7 +111,7 @@ namespace hpx { namespace lcos { namespace detail
template <typename F, typename Args>
struct dataflow_return<F, Args,
typename std::enable_if<!traits::is_action<F>::value>::type
> : util::detail::fused_result_of<F(Args &&)>
> : util::detail::invoke_fused_result<F, Args>
{};

template <typename Action, typename Args>
Expand Down
8 changes: 4 additions & 4 deletions hpx/lcos/future.hpp
Expand Up @@ -615,7 +615,7 @@ namespace hpx { namespace lcos { namespace detail
}

typedef
typename hpx::util::result_of<F(Derived)>::type
typename hpx::util::invoke_result<F, Derived>::type
continuation_result_type;
typedef
typename hpx::traits::detail::shared_state_ptr<result_type>::type
Expand Down Expand Up @@ -645,7 +645,7 @@ namespace hpx { namespace lcos { namespace detail
}

typedef
typename hpx::util::result_of<F(Derived)>::type
typename hpx::util::invoke_result<F, Derived>::type
continuation_result_type;
typedef
typename hpx::traits::detail::shared_state_ptr<result_type>::type
Expand Down Expand Up @@ -679,7 +679,7 @@ namespace hpx { namespace lcos { namespace detail
}

typedef
typename hpx::util::result_of<F(Derived)>::type
typename hpx::util::invoke_result<F, Derived>::type
continuation_result_type;
typedef
typename hpx::traits::detail::shared_state_ptr<result_type>::type
Expand Down Expand Up @@ -1340,7 +1340,7 @@ namespace hpx { namespace lcos
make_future(hpx::shared_future<U> const& f, Conv && conv)
{
static_assert(
hpx::traits::is_callable<Conv(U), R>::value,
hpx::traits::is_invocable_r<R, Conv, U>::value,
"the argument type must be convertible to the requested "
"result type by using the supplied conversion function");

Expand Down
10 changes: 5 additions & 5 deletions hpx/lcos/local/packaged_continuation.hpp
Expand Up @@ -102,12 +102,12 @@ namespace hpx { namespace lcos { namespace detail
template <typename Func, typename Future, typename Continuation>
typename std::enable_if<
!traits::detail::is_unique_future<
typename util::result_of<Func(Future)>::type
typename util::invoke_result<Func, Future>::type
>::value
>::type invoke_continuation(Func& func, Future& future, Continuation& cont)
{
typedef std::is_void<
typename util::result_of<Func(Future)>::type
typename util::invoke_result<Func, Future>::type
> is_void;

hpx::util::annotate_function annotate(func);
Expand All @@ -118,13 +118,13 @@ namespace hpx { namespace lcos { namespace detail
template <typename Func, typename Future, typename Continuation>
typename std::enable_if<
traits::detail::is_unique_future<
typename util::result_of<Func(Future)>::type
typename util::invoke_result<Func, Future>::type
>::value
>::type invoke_continuation(Func& func, Future& future, Continuation& cont)
{
try {
typedef
typename util::result_of<Func(Future)>::type
typename util::invoke_result<Func, Future>::type
inner_future;
typedef
typename traits::detail::shared_state_ptr_for<inner_future>::type
Expand Down Expand Up @@ -286,7 +286,7 @@ namespace hpx { namespace lcos { namespace detail
Future future = traits::future_access<Future>::create(std::move(f));

typedef std::is_void<
typename util::result_of<F(Future)>::type
typename util::invoke_result<F, Future>::type
> is_void;
invoke_continuation(f_, future, *this, is_void());

Expand Down
4 changes: 2 additions & 2 deletions hpx/lcos/local/packaged_task.hpp
Expand Up @@ -43,7 +43,7 @@ namespace hpx { namespace lcos { namespace local
typename F, typename FD = typename std::decay<F>::type,
typename Enable = typename std::enable_if<
!std::is_same<FD, packaged_task>::value
&& traits::is_callable<FD&(Ts...), R>::value
&& traits::is_invocable_r<R, FD&, Ts...>::value
>::type
>
explicit packaged_task(F&& f)
Expand All @@ -56,7 +56,7 @@ namespace hpx { namespace lcos { namespace local
typename F, typename FD = typename std::decay<F>::type,
typename Enable = typename std::enable_if<
!std::is_same<FD, packaged_task>::value
&& traits::is_callable<FD&(Ts...), R>::value
&& traits::is_invocable_r<R, FD&, Ts...>::value
>::type
>
explicit packaged_task(std::allocator_arg_t, Allocator const& a, F && f)
Expand Down

0 comments on commit 67870fc

Please sign in to comment.