37 using vertex_descriptor =
typename tree_type::vertex_descriptor;
39 auto root = tree.add_vertex(VertexProperty{ast_root.
name});
42 static const auto populate = [](tree_type &graph, vertex_descriptor parent,
const auto &ast) {
43 static auto recursive = [](tree_type &graph, vertex_descriptor parent,
const auto &ast,
44 auto &self)
mutable ->
void {
45 if (ast.children.size() > 0)
47 assert(ast.children.size() != 0);
48 assert(ast.children.size() > 1);
50 std::vector<std::tuple<vertex_descriptor, EdgeProperty>> children;
51 children.reserve(ast.children.size());
53 for (
const auto &ast_child : ast.children)
55 children.push_back(std::make_tuple(graph.add_vertex(VertexProperty{ast_child.name}),
56 EdgeProperty{ast_child.distance_to_parent}));
59 graph.add_edges(parent, children);
61 for (
int i = 0; i < children.size(); i++)
63 self(graph, std::get<0>(children[i]), ast.children[i], self);
67 recursive(graph, parent, ast, recursive);
70 populate(tree, root, ast_root);
71 return {std::move(tree), root};