Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Florian_J_
Beginner
44 Views

Why do function nodes require a copyable body?

Jump to solution

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
44 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

1 Reply
45 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

Reply