#include "gdwg_graph.h" #include #include auto main() -> int { /* auto g = gdwg::graph{}; g.insert_node("hello"); g.insert_node("how"); g.insert_node("are"); g.insert_node("you?"); g.insert_edge("hello", "how", 5); g.insert_edge("hello", "are", 8); g.insert_edge("hello", "are", 2); g.insert_edge("how", "you?", 1); g.insert_edge("how", "hello", 4); g.insert_edge("are", "you?", 3); std::cout << g << "\n"; auto g2 = gdwg::graph(g); std::cout << g2 << "\n"; // This is a structured binding. // https://en.cppreference.com/w/cpp/language/structured_binding // It allows you to unpack your tuple. for (const auto& [from, to, weight] : g) { std::cout << from << " -> " << to << " "; if (weight.has_value()) { std::cout << "(weight " << *weight << ")\n"; } else { std::cout << "(no weight)\n"; } } */ using graph = gdwg::graph; auto const v = std::vector>>{ {4, 1, -4}, {3, 2, 2}, {2, 4, std::nullopt}, {2, 4, 2}, {2, 1, 1}, {4, 1, std::nullopt}, {6, 2, 5}, {6, 3, 10}, {1, 5, -1}, {3, 6, -8}, {4, 5, 3}, {5, 2, std::nullopt}, }; auto g = graph{}; for (const auto& [from, to, weight] : v) { g.insert_node(from); g.insert_node(to); if (weight.has_value()) { g.insert_edge(from, to, weight.value()); } else { g.insert_edge(from, to); } } g.insert_node(64); auto out = std::ostringstream{}; out << g; std::cout << g << '\n'; }