diff --git a/gtsam/discrete/DecisionTree-inl.h b/gtsam/discrete/DecisionTree-inl.h index 51d66c860..f3b0dbf3a 100644 --- a/gtsam/discrete/DecisionTree-inl.h +++ b/gtsam/discrete/DecisionTree-inl.h @@ -19,22 +19,24 @@ #pragma once -#include #include +#include +#include +#include #include +#include #include #include -#include -using boost::assign::operator+=; +#include #include -#include - -#include #include #include +#include #include +using boost::assign::operator+=; + namespace gtsam { /*********************************************************************************/ @@ -75,11 +77,33 @@ namespace gtsam { return (q.isLeaf() && q.sameLeaf(*this)); } + /// @{ + /// SFINAE methods for proper substitution. + /** equality for integral types. */ + template + typename std::enable_if::value, bool>::type + equals(const T& a, const T& b, double tol) const { + return std::abs(double(a - b)) < tol; + } + /** equality for boost::shared_ptr types. */ + template + typename std::enable_if::value, bool>::type + equals(const T& a, const T& b, double tol) const { + return traits::Equals(*a, *b, tol); + } + /** equality for all other types. */ + template + typename std::enable_if::value && !std::is_integral::value, bool>::type + equals(const Y& a, const Y& b, double tol) const { + return traits::Equals(a, b, tol); + } + /// @} + /** equality up to tolerance */ bool equals(const Node& q, double tol) const override { const Leaf* other = dynamic_cast(&q); if (!other) return false; - return this->constant_ == other->constant_; + return this->equals(this->constant_, other->constant_, tol); } /** print */