From 7be6ac0e8c180a0f8fe408664601ec8e07b4bc67 Mon Sep 17 00:00:00 2001 From: dellaert Date: Sun, 28 Sep 2014 10:22:19 +0200 Subject: [PATCH] Now compiles but product construction fails because optional derivatives can't be delivered by the operator*() --- gtsam_unstable/base/tests/testBAD.cpp | 39 ++++++++++++++------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/gtsam_unstable/base/tests/testBAD.cpp b/gtsam_unstable/base/tests/testBAD.cpp index 558510970..0bbd02895 100644 --- a/gtsam_unstable/base/tests/testBAD.cpp +++ b/gtsam_unstable/base/tests/testBAD.cpp @@ -292,24 +292,6 @@ public: root_.reset(new BinaryExpression(f, expression1, expression2)); } - // http://stackoverflow.com/questions/16260445/boost-bind-to-operator - template - struct apply_product { - typedef R result_type; - template - R operator()(E1 const& x, E2 const& y) const { - return x * y; - } - }; - - /// Construct a product expression, assumes E1::operator*() exists - template - friend Expression operator*(const Expression& expression1, const Expression& expression2) { - using namespace boost; - boost::bind(apply_product,_1,_2); - return Expression(boost::bind(apply_product,_1,_2),expression1, expression2); - } - /// Return keys that play in this expression std::set keys() const { return root_->keys(); @@ -327,6 +309,23 @@ public: private: boost::shared_ptr > root_; }; + +// http://stackoverflow.com/questions/16260445/boost-bind-to-operator +template +struct apply_product { + typedef E2 result_type; + E2 operator()(E1 const& x, E2 const& y) const { + return x * y; + } +}; + +/// Construct a product expression, assumes E1 * E2 -> E1 +template +Expression operator*(const Expression& expression1, const Expression& expression2) { + using namespace boost; + return Expression(boost::bind(apply_product(),_1,_2),expression1, expression2); +} + //----------------------------------------------------------------------------- void printPair(std::pair pair) { @@ -471,7 +470,9 @@ TEST(BAD, test) { TEST(BAD, rotate) { Expression R(1); Expression p(2); - Expression q = R * p; + // fails because optional derivatives can't be delivered by the operator + // Need a convention for products like these. "act" ? + // Expression q = R * p; } /* ************************************************************************* */