diff --git a/CMakeLists.txt b/CMakeLists.txt index fc9cd2e36..90ac89aa8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,9 +59,9 @@ endif() include(cmake/HandleGeneralOptions.cmake) # CMake build options # Libraries: -if (NOT GTSAM_NO_BOOST_CPP17) +# if (NOT GTSAM_NO_BOOST_CPP17) include(cmake/HandleBoost.cmake) # Boost -endif() +# endif() include(cmake/HandleCCache.cmake) # ccache include(cmake/HandleCPack.cmake) # CPack diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index 3be0a5f7c..2d2b7aa4d 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -40,10 +40,11 @@ namespace gtsam { #ifdef NO_BOOST_CPP17 // These typedefs and aliases will help with making the evaluateError interface // independent of boost -using OptionalNone = nullptr; +using OptionalNoneType = std::nullptr_t; +#define OptionalNone = nullptr template -using OptionalMatrixT = Matrix*; -using OptionalMatrix = Matrix*; +using OptionalMatrixTypeT = Matrix*; +using OptionalMatrixType = Matrix*; // These typedefs and aliases will help with making the unwhitenedError interface // independent of boost using OptionalMatrixVec = std::vector*; @@ -52,8 +53,8 @@ using OptionalMatrixVec = std::vector*; using OptionalNoneType = boost::none_t; #define OptionalNone boost::none template -using OptionalMatrixT = boost::optional; -using OptionalMatrix = boost::optional; +using OptionalMatrixTypeT = boost::optional; +using OptionalMatrixType = boost::optional; using OptionalMatrixVec = boost::optional&>; #endif /** @@ -596,7 +597,7 @@ protected: * @param[out] H The Jacobian with respect to each variable (optional). */ virtual Vector evaluateError(const ValueTypes&... x, - OptionalMatrixT... H) const = 0; + OptionalMatrixTypeT... H) const = 0; /// @} @@ -610,7 +611,7 @@ protected: * e.g. `const Vector error = factor.evaluateError(pose, point);` */ inline Vector evaluateError(const ValueTypes&... x) const { - return evaluateError(x..., OptionalMatrixT()...); + return evaluateError(x..., OptionalMatrixTypeT()...); } /** Some (but not all) optional Jacobians are omitted (function overload) @@ -619,11 +620,30 @@ protected: */ template > inline Vector evaluateError(const ValueTypes&... x, OptionalJacArgs&&... H) const { - constexpr bool are_all_mat = (... && (std::is_same>::value || - std::is_same>::value || +#ifdef NO_BOOST_CPP17 + // A check to ensure all arguments passed are all either matrices or are all pointers to matrices + constexpr bool are_all_mat = (... && (std::is_same>::value)); + constexpr bool are_all_ptrs = (... && (std::is_same>::value || + std::is_same>::value)); + static_assert((are_all_mat || are_all_ptrs), + "Arguments that are passed to the evaluateError function can only be of following the types: Matrix, " + "or Matrix*"); + // if they pass all matrices then we want to pass their pointers instead + if constexpr (are_all_mat) { + return evaluateError(x..., (&OptionalJacArgs)...); + } else { + return evaluateError(x..., std::forward(H)..., static_cast(OptionalNone)); + } +#else + // A check to ensure all arguments passed are all either matrices or are optionals of matrix references + constexpr bool are_all_mat = (... && (std::is_same::value || + std::is_same>::value || std::is_same>::value)); - static_assert(are_all_mat, "ERRORRR"); - return evaluateError(x..., std::forward(H)..., boost::none); + static_assert(are_all_mat, + "Arguments that are passed to the evaluateError function can only be of following the types: Matrix&, " + "boost::optional, or boost::none_t"); + return evaluateError(x..., std::forward(H)..., OptionalNone); +#endif } /// @} diff --git a/gtsam/nonlinear/tests/CMakeLists.txt b/gtsam/nonlinear/tests/CMakeLists.txt index 69a3700f2..4a4aff4b4 100644 --- a/gtsam/nonlinear/tests/CMakeLists.txt +++ b/gtsam/nonlinear/tests/CMakeLists.txt @@ -1 +1 @@ -gtsamAddTestsGlob(nonlinear "test*.cpp" "" "gtsam") +gtsamAddTestsGlob(nonlinear "test*.cpp" "${tests_exclude}" "gtsam")