Hi,
I am trying to return an object of a component client from an action
defined in another component. Passing the same object in action as argument
seems to work fine, but returning produces an error. What is the correct
way of doing it ?

Minimal code for what I want :

#include <hpx/hpx_init.hpp>
#include <hpx/include/actions.hpp>
#include <hpx/include/components.hpp>

#include <utility>

struct foo_server : public hpx::components::component_base<foo_server>
{
};

using foo_server_type = hpx::components::component<foo_server>;
HPX_REGISTER_COMPONENT(foo_server_type, foo_server);

struct foo : public hpx::components::client_base<foo, foo_server>
{
   public:
   using base_type = hpx::components::client_base<foo, foo_server>;

   foo() = default;

   foo(hpx::id_type id) : base_type(std::move(id))
   {
   }

};

struct bar_server : public hpx::components::component_base<bar_server>
{
   foo get_foo() {
       //return hpx::new_<foo_server>(hpx::find_here());
       return foo(hpx::find_here());
   }
   HPX_DEFINE_COMPONENT_DIRECT_ACTION(bar_server, get_foo, get_foo_action);
};
using bar_server_type = hpx::components::component<bar_server>;
HPX_REGISTER_COMPONENT(bar_server_type, bar_server);

HPX_REGISTER_ACTION(bar_server::get_foo_action);

struct bar : public hpx::components::client_base<bar, bar_server>
{
   public:
   using base_type = hpx::components::client_base<bar, bar_server>;

   bar() = default;

   bar(hpx::id_type id) : base_type(std::move(id))
   {
   }

   hpx::future<foo> get_foo() {
       bar_server::get_foo_action act;
       // This async statement gives compilation error
       return hpx::async(act, hpx::find_here());
   }

};

int hpx_main(int, char*[])
{

   bar b(hpx::find_here());
   auto res = b.get_foo().get();

   return hpx::finalize();
}

int main(int argc, char* argv[])
{
  return hpx::init(argc, argv);
}


Compilation fails with error :

test.cpp: In member function ‘hpx::lcos::future<foo> bar::get_foo()’:
test.cpp:54:26: error: could not convert ‘hpx::async(F&&, Ts&& ...) [with F
= bar_server::get_foo_action&; Ts = {hpx::naming::id_type}; decltype
(hpx::detail::async_dispatch<type
name hpx::util::decay<Action>::type>::call(forward<F>(f),
(forward<Ts>)(hpx::async::ts)...)) =
hpx::lcos::future<hpx::naming::id_type>; typename
hpx::util::decay<Action>::type =
bar_server::get_foo_action](hpx::find_here(hpx::error_code&)())’ from ‘
hpx::lcos::future<hpx::naming::id_type>’ to ‘hpx::lcos::future<foo>’
        return hpx::async(act, hpx::find_here());



Thanks
Vineet
_______________________________________________
hpx-users mailing list
[email protected]
https://mail.cct.lsu.edu/mailman/listinfo/hpx-users

Reply via email to