/
action_decorate_function.hpp
73 lines (63 loc) · 2.37 KB
/
action_decorate_function.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright (c) 2007-2016 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#if !defined(HPX_TRAITS_ACTION_DECORATE_FUNCTION_MAR_30_2014_1054AM)
#define HPX_TRAITS_ACTION_DECORATE_FUNCTION_MAR_30_2014_1054AM
#include <hpx/runtime/naming_fwd.hpp>
#include <hpx/runtime/threads/thread_data_fwd.hpp>
#include <hpx/traits/detail/wrap_int.hpp>
#include <hpx/traits/has_xxx.hpp>
#include <hpx/util/unique_function.hpp>
#include <utility>
namespace hpx { namespace traits
{
///////////////////////////////////////////////////////////////////////////
// Customization point for action capabilities
namespace detail
{
struct decorate_function_helper
{
// by default we return the unchanged function
template <typename Action, typename F>
static threads::thread_function_type
call(wrap_int, naming::address_type lva, F && f)
{
return std::forward<F>(f);
}
// forward the call if the component implements the function
template <typename Action, typename F>
static auto
call(int, naming::address_type lva, F && f)
-> decltype(
Action::component_type::decorate_action(
lva, std::forward<F>(f))
)
{
typedef typename Action::component_type component_type;
return component_type::decorate_action(lva, std::forward<F>(f));
}
};
template <typename Action, typename F>
threads::thread_function_type
call_decorate_function(naming::address_type lva, F && f)
{
return decorate_function_helper::template call<Action>(
0, lva, std::forward<F>(f));
}
HPX_HAS_XXX_TRAIT_DEF(decorates_action);
}
template <typename Action, typename Enable = void>
struct action_decorate_function
{
static constexpr bool value = detail::has_decorates_action<Action>::value;
template <typename F>
static threads::thread_function_type
call(naming::address_type lva, F && f)
{
return detail::call_decorate_function<Action>(
lva, std::forward<F>(f));
}
};
}}
#endif