Skip to content

Commit 275a67d

Browse files
authored
Merge pull request #7298 from Priyanshi507/reflect-action-auto-register
actions_base: add auto-registration to reflect_action
2 parents eecb31f + be7ecae commit 275a67d

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

libs/full/actions_base/include/hpx/actions_base/reflect_action.hpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#if defined(HPX_HAVE_CXX26_REFLECTION)
1515

1616
#include <hpx/actions_base/basic_action.hpp>
17+
#include <hpx/actions_base/detail/invocation_count_registry.hpp>
1718
#include <hpx/actions_base/plain_action.hpp>
1819
#include <hpx/modules/serialization.hpp>
1920

@@ -46,13 +47,16 @@ namespace hpx::actions {
4647
/// reflect_action<F> integrates with HPX's action system by inheriting
4748
/// from basic_action<detail::plain_function, R(Ps...), reflect_action<F>>.
4849
/// All properties are derived automatically from the reflected function F.
50+
/// Invocation count registration is automatic via a static member --
51+
/// no HPX_REGISTER_ACTION call is needed for reflection-based actions.
4952
///
5053
/// \tparam F A std::meta::info reflection of a free function.
51-
template <std::meta::info F>
54+
/// \tparam Derived Derived type for CRTP extensibility (default: void).
55+
template <std::meta::info F, typename Derived = void>
5256
struct reflect_action
5357
: basic_action<hpx::actions::detail::plain_function,
5458
typename detail::reflect_action_base<F>::func_type,
55-
reflect_action<F>>
59+
detail::action_type_t<reflect_action<F, Derived>, Derived>>
5660
{
5761
/// The function type (e.g. int(double, double))
5862
using func_type = [:std::meta::type_of(F):];
@@ -81,12 +85,23 @@ namespace hpx::actions {
8185
naming::address::component_type /*comptype*/, Ts&&... vs)
8286
{
8387
using base_t = basic_action<hpx::actions::detail::plain_function,
84-
func_type, reflect_action<F>>;
88+
func_type, detail::action_type_t<reflect_action, Derived>>;
8589
base_t::increment_invocation_count();
8690
return func_ptr(HPX_FORWARD(Ts, vs)...);
8791
}
92+
93+
/// Automatic invocation count registration -- eliminates the need
94+
/// for HPX_REGISTER_ACTION for reflection-based plain actions.
95+
static detail::register_action_invocation_count<reflect_action>
96+
invocation_count_registrar_;
8897
};
8998

99+
/// \cond NOINTERNAL
100+
template <std::meta::info F, typename Derived>
101+
detail::register_action_invocation_count<reflect_action<F, Derived>>
102+
reflect_action<F, Derived>::invocation_count_registrar_;
103+
/// \endcond
104+
90105
} // namespace hpx::actions
91106

92107
#endif // HPX_HAVE_CXX26_REFLECTION

libs/full/actions_base/tests/unit/reflect_action_test.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include <cstddef>
1515
#include <string>
16+
#include <type_traits>
1617

1718
namespace app {
1819

@@ -89,5 +90,15 @@ int main()
8990
HPX_TEST_EQ(compute_action::func_ptr(3.0, 4.0), 7);
9091
}
9192

93+
// Test: auto-registration static member exists (compile-time check)
94+
// This verifies that reflect_action has the invocation_count_registrar_
95+
// static member which enables automatic registration without HPX_REGISTER_ACTION
96+
{
97+
HPX_ACTION(app::compute, compute_action);
98+
using registrar_type =
99+
decltype(compute_action::invocation_count_registrar_);
100+
static_assert(!std::is_void_v<registrar_type>,
101+
"invocation_count_registrar_ must exist");
102+
}
92103
return hpx::util::report_errors();
93104
}

0 commit comments

Comments
 (0)