Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

Why do function nodes require a copyable body?

Florian_J_
Beginner
337 Views

Hi,

I tried to create a tbb::flow::function_node on a move-only type, e.g.

#include <tbb/flow_graph.h>

class MyType {
 public:
  MyType() = default;
  MyType(const MyType&) = delete;
  MyType& operator=(const MyType&) = delete;
  MyType(MyType&&) = default;
  MyType& operator=(MyType&&) = default;
  ~MyType() = default;
};

int main() {
  tbb::flow::graph g;
  tbb::flow::function_node<int, int> {
      g, 1, MyType{}
  };
}

However, this does not work, because function_body_leaf stores a copy of the body. Why is this necessary? Is it possible, to use move-only types with tbb::flow? 

Best regards,

Florian

 

 

0 Kudos
1 Solution
Christophe_H_Intel
337 Views

Hi, Florian,

There are several features of the body of function_node which disallow move-only bodies.

  • After a graph has executed, one can fetch the current state of the body to examine it.  A move-only body would leave the function_node without a body to execute.
  • copy-construction
  • re-initialization of the node body with a copy made at construction time.

Regards,
Chris

View solution in original post

0 Kudos
1 Reply
Christophe_H_Intel
338 Views

Hi, Florian,

There are several features of the body of function_node which disallow move-only bodies.

  • After a graph has executed, one can fetch the current state of the body to examine it.  A move-only body would leave the function_node without a body to execute.
  • copy-construction
  • re-initialization of the node body with a copy made at construction time.

Regards,
Chris

0 Kudos
Reply