From 8c7e75bb25d0be16efada3c5ac7733ca12e58367 Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Tue, 28 Jan 2025 14:50:11 -0500 Subject: [PATCH] Review comments --- gtsam/discrete/DiscreteJunctionTree.cpp | 26 +++++++++---------------- gtsam/discrete/tests/AsiaExample.h | 2 +- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/gtsam/discrete/DiscreteJunctionTree.cpp b/gtsam/discrete/DiscreteJunctionTree.cpp index e1fc2af11..bf9f9fe18 100644 --- a/gtsam/discrete/DiscreteJunctionTree.cpp +++ b/gtsam/discrete/DiscreteJunctionTree.cpp @@ -31,26 +31,18 @@ DiscreteJunctionTree::DiscreteJunctionTree( const DiscreteEliminationTree& eliminationTree) : Base(eliminationTree) {} /* ************************************************************************* */ -namespace { -struct PrintForestVisitorPre { - const KeyFormatter& formatter; - PrintForestVisitorPre(const KeyFormatter& formatter) : formatter(formatter) {} - std::string operator()( - const std::shared_ptr& node, - const std::string& parentString) { - // Print the current node - node->print(parentString + "-", formatter); - node->factors.print(parentString + "-", formatter); - std::cout << std::endl; - // Increment the indentation - return parentString + "| "; - } -}; -} // namespace void DiscreteJunctionTree::print(const std::string& s, const KeyFormatter& keyFormatter) const { - PrintForestVisitorPre visitor(keyFormatter); + auto visitor = [&keyFormatter]( + const std::shared_ptr& node, + const std::string& parentString) { + // Print the current node + node->print(parentString + "-", keyFormatter); + node->factors.print(parentString + "-", keyFormatter); + std::cout << std::endl; + return parentString + "| "; // Increment the indentation + }; std::string parentString = s; treeTraversal::DepthFirstForest(*this, parentString, visitor); } diff --git a/gtsam/discrete/tests/AsiaExample.h b/gtsam/discrete/tests/AsiaExample.h index 6c327daec..ff6c4ea99 100644 --- a/gtsam/discrete/tests/AsiaExample.h +++ b/gtsam/discrete/tests/AsiaExample.h @@ -58,4 +58,4 @@ DiscreteBayesNet createAsiaExample() { return asia; } } // namespace asia_example -} // namespace gtsam \ No newline at end of file +} // namespace gtsam