From 35281737817c2712a814f579287ba84d40ca5f4e Mon Sep 17 00:00:00 2001 From: Richard Roberts Date: Thu, 8 Aug 2013 16:29:55 +0000 Subject: [PATCH] Fixed compile problem on linux using boost::join with boost::cref_list_of --- .cproject | 2 +- gtsam/base/types.h | 26 ++++++++++++++++++++++++++ gtsam/inference/BayesTree-inst.h | 1 + gtsam/linear/GaussianConditional-inl.h | 2 +- gtsam/linear/HessianFactor.cpp | 6 ++++-- gtsam/linear/JacobianFactor-inl.h | 6 ++---- gtsam/linear/JacobianFactor.cpp | 2 +- 7 files changed, 36 insertions(+), 9 deletions(-) diff --git a/.cproject b/.cproject index 7257e427d..02f7b71c6 100644 --- a/.cproject +++ b/.cproject @@ -19,7 +19,7 @@ - + diff --git a/gtsam/base/types.h b/gtsam/base/types.h index 6ca9b9ea1..5a9ee28a3 100644 --- a/gtsam/base/types.h +++ b/gtsam/base/types.h @@ -25,6 +25,7 @@ #include #include +#include namespace gtsam { @@ -103,6 +104,31 @@ namespace gtsam { operator T() const { return value; } }; + /** A helper class that behaves as a container with one element, and works with + * boost::range */ + template + class ListOfOneContainer { + T element_; + public: + typedef T value_type; + typedef const T* const_iterator; + typedef T* iterator; + ListOfOneContainer(const T& element) : element_(element) {} + const T* begin() const { return &element_; } + const T* end() const { return &element_ + 1; } + T* begin() { return &element_; } + T* end() { return &element_ + 1; } + size_t size() const { return 1; } + }; + + BOOST_CONCEPT_ASSERT((boost::RandomAccessRangeConcept >)); + + /** Factory function for ListOfOneContainer to enable ListOfOne(e) syntax. */ + template + ListOfOneContainer ListOfOne(const T& element) { + return ListOfOneContainer(element); + } + /** An assertion that throws an exception if NDEBUG is not defined and * evaluates to an empty statement otherwise. */ #ifdef NDEBUG diff --git a/gtsam/inference/BayesTree-inst.h b/gtsam/inference/BayesTree-inst.h index 3b31906b2..6a303e081 100644 --- a/gtsam/inference/BayesTree-inst.h +++ b/gtsam/inference/BayesTree-inst.h @@ -146,6 +146,7 @@ namespace gtsam { } /* ************************************************************************* */ + // TODO: Clean up namespace { template int _pushClique(FactorGraph& fg, const boost::shared_ptr& clique) { diff --git a/gtsam/linear/GaussianConditional-inl.h b/gtsam/linear/GaussianConditional-inl.h index f9a925d23..6fe7bd642 100644 --- a/gtsam/linear/GaussianConditional-inl.h +++ b/gtsam/linear/GaussianConditional-inl.h @@ -29,7 +29,7 @@ namespace gtsam { GaussianConditional::GaussianConditional(Index key, const Vector& d, const Matrix& R, const PARENTS& parents, const SharedDiagonal& sigmas, const typename PARENTS::value_type*) : BaseFactor(boost::join( - boost::assign::cref_list_of<1,typename PARENTS::value_type>(std::make_pair(key, R)), + ListOfOne(std::make_pair(key, R)), parents), d, sigmas), BaseConditional(1) {} diff --git a/gtsam/linear/HessianFactor.cpp b/gtsam/linear/HessianFactor.cpp index 7302b0880..d865bf589 100644 --- a/gtsam/linear/HessianFactor.cpp +++ b/gtsam/linear/HessianFactor.cpp @@ -168,12 +168,14 @@ GaussianFactor(cref_list_of<3>(j1)(j2)(j3)), } /* ************************************************************************* */ -namespace { DenseIndex _getSizeHF(const Vector& m) { return m.size(); } } +namespace { + DenseIndex _getSizeHF(const Vector& m) { return m.size(); } +} /* ************************************************************************* */ HessianFactor::HessianFactor(const std::vector& js, const std::vector& Gs, const std::vector& gs, double f) : -GaussianFactor(js), info_(br::join(gs | br::transformed(&_getSizeHF), cref_list_of<1,DenseIndex>(1))) +GaussianFactor(js), info_(br::join(gs | br::transformed(&_getSizeHF), ListOfOne((DenseIndex)1))) { // Get the number of variables size_t variable_count = js.size(); diff --git a/gtsam/linear/JacobianFactor-inl.h b/gtsam/linear/JacobianFactor-inl.h index fb66be882..fb9582f24 100644 --- a/gtsam/linear/JacobianFactor-inl.h +++ b/gtsam/linear/JacobianFactor-inl.h @@ -21,7 +21,6 @@ #include #include #include -#include #include namespace gtsam { @@ -71,7 +70,7 @@ namespace gtsam { void JacobianFactor::fillTerms(const TERMS& terms, const Vector& b, const SharedDiagonal& noiseModel) { // Check noise model dimension - if(noiseModel && noiseModel->dim() != b.size()) + if(noiseModel && (DenseIndex)noiseModel->dim() != b.size()) throw InvalidNoiseModel(b.size(), noiseModel->dim()); // Resize base class key vector @@ -82,9 +81,8 @@ namespace gtsam { // a single '1' to add a dimension for the b vector. { using boost::adaptors::transformed; - using boost::assign::cref_list_of; namespace br = boost::range; - Ab_ = VerticalBlockMatrix(br::join(terms | transformed(&_getColsJF), cref_list_of<1,DenseIndex>(1)), b.size()); + Ab_ = VerticalBlockMatrix(br::join(terms | transformed(&_getColsJF), ListOfOne((DenseIndex)1)), b.size()); } // Check and add terms diff --git a/gtsam/linear/JacobianFactor.cpp b/gtsam/linear/JacobianFactor.cpp index 2b154958b..be2636a16 100644 --- a/gtsam/linear/JacobianFactor.cpp +++ b/gtsam/linear/JacobianFactor.cpp @@ -265,7 +265,7 @@ namespace gtsam { // Allocate matrix and copy keys in order gttic(allocate); - Ab_ = VerticalBlockMatrix(boost::join(varDims, cref_list_of<1,DenseIndex>(1)), m); // Allocate augmented matrix + Ab_ = VerticalBlockMatrix(boost::join(varDims, ListOfOne((DenseIndex)1)), m); // Allocate augmented matrix Base::keys_.resize(orderedSlots.size()); boost::range::copy( // Get variable keys orderedSlots | boost::adaptors::indirected | boost::adaptors::map_keys, Base::keys_.begin());