diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index ca13434a1..3a59a4db3 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -29,6 +29,9 @@ #include #include +// boost::index_sequence was introduced in 1.66, so we'll manually define an +// implementation if user has 1.65. boost::index_sequence is used to get array +// indices that align with a parameter pack. #if BOOST_VERSION >= 106600 #include #else @@ -467,24 +470,11 @@ class NoiseModelFactorN ~NoiseModelFactorN() override {} - /** Methods to retrieve keys */ -#define SUB(Old, New) template // to delay template deduction -#define KEY_IF_TRUE(Enable) typename std::enable_if<(Enable), Key>::type - // templated version of `key()` + /** Returns a key. Usage: `key()` returns the I'th key. */ template - inline KEY_IF_TRUE(I < N) key() const { + inline typename std::enable_if<(I < N), Key>::type key() const { return keys_[I]; } - // backwards-compatibility functions - SUB(T, N) inline KEY_IF_TRUE(T == 1) key() const { return keys_[0]; } - SUB(T, N) inline KEY_IF_TRUE(T >= 1) key1() const { return keys_[0]; } - SUB(T, N) inline KEY_IF_TRUE(T >= 2) key2() const { return keys_[1]; } - SUB(T, N) inline KEY_IF_TRUE(T >= 3) key3() const { return keys_[2]; } - SUB(T, N) inline KEY_IF_TRUE(T >= 4) key4() const { return keys_[3]; } - SUB(T, N) inline KEY_IF_TRUE(T >= 5) key5() const { return keys_[4]; } - SUB(T, N) inline KEY_IF_TRUE(T >= 6) key6() const { return keys_[5]; } -#undef SUB -#undef KEY_IF_TRUE /// @name NoiseModelFactor methods /// @{ @@ -583,6 +573,32 @@ class NoiseModelFactorN ar& boost::serialization::make_nvp( "NoiseModelFactor", boost::serialization::base_object(*this)); } + + public: + /** @defgroup deprecated key access + * Functions to retrieve keys (deprecated). Use the templated version: + * `key()` instead. + * @{ + */ +#define SUB(Old, New) template // to delay template deduction +#define KEY_IF_TRUE(Enable) typename std::enable_if<(Enable), Key>::type + /** @deprecated */ + SUB(T, N) inline KEY_IF_TRUE(T == 1) key() const { return keys_[0]; } + /** @deprecated */ + SUB(T, N) inline KEY_IF_TRUE(T >= 1) key1() const { return keys_[0]; } + /** @deprecated */ + SUB(T, N) inline KEY_IF_TRUE(T >= 2) key2() const { return keys_[1]; } + /** @deprecated */ + SUB(T, N) inline KEY_IF_TRUE(T >= 3) key3() const { return keys_[2]; } + /** @deprecated */ + SUB(T, N) inline KEY_IF_TRUE(T >= 4) key4() const { return keys_[3]; } + /** @deprecated */ + SUB(T, N) inline KEY_IF_TRUE(T >= 5) key5() const { return keys_[4]; } + /** @deprecated */ + SUB(T, N) inline KEY_IF_TRUE(T >= 6) key6() const { return keys_[5]; } +#undef SUB +#undef KEY_IF_TRUE + /** @} */ }; // \class NoiseModelFactorN /* ************************************************************************* */