Search code examples
c++hpx

Compilation error with hpx::dataflow and member function


What is the correct way to call hpx::dataflow with a member function?

hpx::async works fine, but we can't figure out, why hpx::dataflow doesn't compile.

#include <hpx/hpx_main.hpp>
#include <hpx/hpx.hpp>
#include <memory>

class A {
public:
  A& do_work(double x, const A& y, const A& z) {
    i = x + y.i + z.i;
    return *this;
  }

  double i = 1.0;
};

int main() {
  // Create instances
  std::vector<std::unique_ptr<A>> vec;
  for (int i = 0; i < 3; ++i) {
    vec.emplace_back( std::make_unique<A>() );
  }

  std::vector<hpx::shared_future<A&>> a1(3);
  std::vector<hpx::shared_future<A&>> a2(3);

  // works
  a1[1] = hpx::async( &A::do_work, vec[1].get(), 1.0, *vec[0], *vec[2] );

  // compiler error here
  a2[1] = hpx::dataflow( hpx::util::unwrapping_all( &A::do_work ),
            vec[1].get(), 2.0, a1[0], a2[0] );

  return 0;
}

The compiler error says:

hpx.cpp:29:100:   required from here
.../hpx/hpx/traits/get_remote_result.hpp:25:20: error: invalid cast from type ‘std::remove_reference<A&>::type’ {aka
‘A’} to type ‘A*’ return Result(std::move(rhs));

The used HPX Version is 1.2.0 with GCC 8.1.


Solution

  • This looks like a bug to me. I have created an issue on the repository for this: https://github.com/STEllAR-GROUP/hpx/issues/3639.