1.. _make_edges:
2
3``make_edges`` function template
4================================
5
6.. note::
7   To enable this feature, define the ``TBB_PREVIEW_FLOW_GRAPH_FEATURES`` macro to 1.
8
9.. contents::
10    :local:
11    :depth: 1
12
13Description
14***********
15
16The ``make_edges`` function template creates edges between a single node
17and each node in a set of nodes.
18
19There are two ways to connect nodes in a set and a single node using
20``make_edges``:
21
22.. figure:: ./Resources/make_edges_usage.png
23   :align: center
24
25API
26***
27
28Header
29------
30
31.. code:: cpp
32
33    #include <oneapi/tbb/flow_graph.h>
34
35Syntax
36------
37
38.. code:: cpp
39
40    // node_set is an exposition-only name for the type returned from make_node_set function
41
42    template <typename NodeType, typename Node, typename... Nodes>
43    void make_edges(node_set<Node, Nodes...>& set, NodeType& node);
44
45    template <typename NodeType, typename Node, typename... Nodes>
46    void make_edges(NodeType& node, node_set<Node, Nodes...>& set);
47
48Example
49-------
50
51The example implements the graph structure in the picture below.
52
53.. figure:: ./Resources/make_edges_example.png
54    :align: center
55
56.. code:: cpp
57
58    #define TBB_PREVIEW_FLOW_GRAPH_FEATURES 1
59    #include <oneapi/tbb/flow_graph.h>
60
61    int main() {
62        using namespace oneapi::tbb::flow;
63
64        graph g;
65        broadcast_node<int> input(g);
66
67        function_node doubler(g, unlimited, [](const int& i) { return 2 * i; });
68        function_node squarer(g, unlimited, [](const int& i) { return i * i; });
69        function_node cuber(g, unlimited, [](const int& i) { return i * i * i; });
70
71        buffer_node<int> buffer(g);
72
73        auto handlers = make_node_set(doubler, squarer, cuber);
74        make_edges(input, handlers);
75        make_edges(handlers, buffer);
76
77        for (int i = 1; i <= 10; ++i) {
78            input.try_put(i);
79        }
80        g.wait_for_all();
81    }
82