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