Duncan Tourolle 2bca2a7554
All checks were successful
🧪 Test / test (push) Successful in 6m4s
Add static network
2026-05-08 20:00:15 +02:00

35 lines
1.0 KiB
C++

// Example 10 — Static Hello Pipeline
//
// The same linear pipeline as example 01, built with make_network() instead
// of the runtime Network builder. The topology is fully known at compile time:
// cycle detection is a static_assert, no build() step is needed, and start/stop
// require no virtual dispatch through a string-keyed node map.
//
// [produce] --int--> [double_it] --int--> [print_it]
#include <kpn/kpn.hpp>
#include <chrono>
#include <iostream>
#include <thread>
static int produce() { return 42; }
static int double_it(int x) { return x * 2; }
static void print_it(int x) { std::cout << "result: " << x << '\n'; }
int main() {
using namespace kpn;
auto src = make_node<produce, "src" >(5);
auto dbl = make_node<double_it, "dbl" >(5);
auto sink = make_node<print_it, "sink">(5);
auto net = make_network(
edge(src.output<0>(), dbl.input<0>()),
edge(dbl.output<0>(), sink.input<0>())
);
net.start();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
net.stop();
}