diff --git a/CMakeLists.txt b/CMakeLists.txt index 710d84d28..994f295e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,8 +7,10 @@ if(NOT DEFINED CMAKE_MACOSX_RPATH) endif() option(GTSAM_NO_BOOST_CPP17 "Require and use boost" ON) +add_definitions(-Wno-deprecated-declarations) if (GTSAM_NO_BOOST_CPP17) + add_definitions(-DNO_BOOST_CPP17) set(CMAKE_CXX_STANDARD 17) endif() @@ -57,9 +59,8 @@ endif() include(cmake/HandleGeneralOptions.cmake) # CMake build options # Libraries: -if (GTSAM_NO_BOOST_CPP17) +if (NOT GTSAM_NO_BOOST_CPP17) include(cmake/HandleBoost.cmake) # Boost - add_definitions(-DNO_BOOST_CPP17) endif() include(cmake/HandleCCache.cmake) # ccache diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index 9ccd0246f..acaa24424 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -33,7 +33,28 @@ namespace gtsam { /* ************************************************************************* */ - +/* + * Some typedef based aliases to compile these interfaces without boost if + * the NO_BOOST_C17 flag is enabled + */ +#ifdef NO_BOOST_CPP17 +// These typedefs and aliases will help with making the evaluateError interface +// independent of boost +#define OptionalNone nullptr +template +using OptionalMatrixT = Matrix*; +using OptionalMatrix = Matrix*; +// These typedefs and aliases will help with making the unwhitenedError interface +// independent of boost +using OptionalMatrixVec = std::vector*; +#else +// creating a none value to use when declaring our interfaces +#define OptionalNone boost::none +template +using OptionalMatrixT = boost::optional; +using OptionalMatrix = boost::optional; +using OptionalMatrixVec = boost::optional&>; +#endif /** * Nonlinear factor base class * @@ -206,7 +227,6 @@ protected: NoiseModelFactor(const SharedNoiseModel& noiseModel) : noiseModel_(noiseModel) {} public: - /** Print */ void print(const std::string& s = "", const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override; @@ -230,8 +250,7 @@ public: * If the optional arguments is specified, it should compute * both the function evaluation and its derivative(s) in H. */ - virtual Vector unwhitenedError(const Values& x, - boost::optional&> H = boost::none) const = 0; + virtual Vector unwhitenedError(const Values& x, OptionalMatrixVec H = OptionalNone) const = 0; /** * Vector of errors, whitened @@ -402,7 +421,7 @@ class NoiseModelFactorN /// N is the number of variables (N-way factor) enum { N = sizeof...(ValueTypes) }; - protected: +protected: using Base = NoiseModelFactor; using This = NoiseModelFactorN; @@ -428,8 +447,6 @@ class NoiseModelFactorN /* Like std::void_t, except produces `boost::optional` instead of * `void`. Used to expand fixed-type parameter-packs with same length as * ValueTypes. */ - template - using OptionalMatrix = boost::optional; /* Like std::void_t, except produces `Key` instead of `void`. Used to expand * fixed-type parameter-packs with same length as ValueTypes. */ @@ -541,7 +558,7 @@ class NoiseModelFactorN */ Vector unwhitenedError( const Values& x, - boost::optional&> H = boost::none) const override { + OptionalMatrixVec H = OptionalNone) const override { return unwhitenedError(boost::mp11::index_sequence_for{}, x, H); } @@ -573,7 +590,7 @@ class NoiseModelFactorN * @param[out] H The Jacobian with respect to each variable (optional). */ virtual Vector evaluateError(const ValueTypes&... x, - OptionalMatrix... H) const = 0; + OptionalMatrixT... H) const = 0; /// @} @@ -587,7 +604,7 @@ class NoiseModelFactorN * e.g. `const Vector error = factor.evaluateError(pose, point);` */ inline Vector evaluateError(const ValueTypes&... x) const { - return evaluateError(x..., OptionalMatrix()...); + return evaluateError(x..., OptionalMatrixT()...); } /** Some (but not all) optional Jacobians are omitted (function overload) @@ -599,7 +616,7 @@ class NoiseModelFactorN inline Vector evaluateError(const ValueTypes&... x, OptionalJacArgs&&... H) const { return evaluateError(x..., std::forward(H)..., - boost::none); + OptionalNone); } /// @} @@ -615,7 +632,7 @@ class NoiseModelFactorN inline Vector unwhitenedError( boost::mp11::index_sequence, // const Values& x, - boost::optional&> H = boost::none) const { + OptionalMatrixVec H = OptionalNone) const { if (this->active(x)) { if (H) { return evaluateError(x.at(keys_[Indices])...,