fix visitWith operator() to be more functional

release/4.3a0
Varun Agrawal 2022-03-18 00:11:38 -04:00
parent 5e9020237f
commit 13c60990f7
2 changed files with 7 additions and 2 deletions

View File

@ -33,6 +33,8 @@ namespace gtsam {
template <class L>
class Assignment : public std::map<L, size_t> {
public:
using std::map<L, size_t>::operator=;
void print(const std::string& s = "Assignment: ") const {
std::cout << s << ": ";
for (const typename Assignment::value_type& keyValue : *this)

View File

@ -666,8 +666,11 @@ namespace gtsam {
if (!choice)
throw std::invalid_argument("DecisionTree::VisitWith: Invalid NodePtr");
for (size_t i = 0; i < choice->nrChoices(); i++) {
choices[choice->label()] = i; // Set assignment for label to i
(*this)(choice->branches()[i]); // recurse!
choices[choice->label()] = i; // Set assignment for label to i
VisitWith<L, Y> visit(f);
visit.choices = choices;
visit(choice->branches()[i]); // recurse!
}
}
};