diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index e1b343218..c58179db3 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -555,31 +555,38 @@ class NoiseModelFactorN : public NoiseModelFactor { } public: - /// @name Deprecated methods + /// @name Deprecated methods. Use `key<1>()`, `key<2>()`, ... instead of old + /// `key1()`, `key2()`, ... + /// If your class is templated AND you are trying to call `key<1>` inside your + /// class, due to dependent types you need to do `this->template key<1>()`. /// @{ - template 1), void>::type> inline Key GTSAM_DEPRECATED key1() const { return key<1>(); } - template > + template inline Key GTSAM_DEPRECATED key2() const { + static_assert(I <= N, "Index out of bounds"); return key<2>(); } - template > + template inline Key GTSAM_DEPRECATED key3() const { + static_assert(I <= N, "Index out of bounds"); return key<3>(); } - template > + template inline Key GTSAM_DEPRECATED key4() const { + static_assert(I <= N, "Index out of bounds"); return key<4>(); } - template > + template inline Key GTSAM_DEPRECATED key5() const { + static_assert(I <= N, "Index out of bounds"); return key<5>(); } - template > + template inline Key GTSAM_DEPRECATED key6() const { + static_assert(I <= N, "Index out of bounds"); return key<6>(); } @@ -588,8 +595,12 @@ class NoiseModelFactorN : public NoiseModelFactor { }; // \class NoiseModelFactorN /* ************************************************************************* */ -/** @deprecated: use NoiseModelFactorN, replacing .key() with .key<1> and X1 - * with ValueType<1>. If your class is templated, use `this->template key<1>()` +/** @deprecated: use NoiseModelFactorN, replacing .key() with .key<1>() and X1 + * with ValueType<1>. + * If your class is templated AND you are trying to call `.key<1>()` or + * `ValueType<1>` inside your class, due to dependent types you need to do + * `this->template key<1>()` or `This::template ValueType<1>`. + * ~~~ * A convenient base class for creating your own NoiseModelFactor * with 1 variable. To derive from this class, implement evaluateError(). */ @@ -613,11 +624,6 @@ class GTSAM_DEPRECATED NoiseModelFactor1 : public NoiseModelFactorN { using NoiseModelFactorN::NoiseModelFactorN; ~NoiseModelFactor1() override {} - /** Method to retrieve key. - * Similar to `ValueType`, you can probably do `return key<1>();` - */ - inline Key key() const { return NoiseModelFactorN::template key<1>(); } - private: /** Serialization function */ friend class boost::serialization::access; @@ -629,8 +635,12 @@ class GTSAM_DEPRECATED NoiseModelFactor1 : public NoiseModelFactorN { }; // \class NoiseModelFactor1 /* ************************************************************************* */ -/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 - * with ValueType<1>. If your class is templated, use `this->template key<1>()` +/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1>() and X1 + * with ValueType<1>. + * If your class is templated AND you are trying to call `.key<1>()` or + * `ValueType<1>` inside your class, due to dependent types you need to do + * `this->template key<1>()` or `This::template ValueType<1>`. + * ~~~ * A convenient base class for creating your own NoiseModelFactor * with 2 variables. To derive from this class, implement evaluateError(). */ @@ -656,12 +666,6 @@ class GTSAM_DEPRECATED NoiseModelFactor2 using NoiseModelFactorN::NoiseModelFactorN; ~NoiseModelFactor2() override {} - /** Methods to retrieve keys. - * Similar to `ValueType`, you can probably do `return key<#>();` - */ - inline Key key1() const { return this->template key<1>(); } - inline Key key2() const { return this->template key<2>(); } - private: /** Serialization function */ friend class boost::serialization::access; @@ -673,8 +677,12 @@ class GTSAM_DEPRECATED NoiseModelFactor2 }; // \class NoiseModelFactor2 /* ************************************************************************* */ -/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 - * with ValueType<1>. If your class is templated, use `this->template key<1>()` +/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1>() and X1 + * with ValueType<1>. + * If your class is templated AND you are trying to call `.key<1>()` or + * `ValueType<1>` inside your class, due to dependent types you need to do + * `this->template key<1>()` or `This::template ValueType<1>`. + * ~~~ * A convenient base class for creating your own NoiseModelFactor * with 3 variables. To derive from this class, implement evaluateError(). */ @@ -701,13 +709,6 @@ class GTSAM_DEPRECATED NoiseModelFactor3 using NoiseModelFactorN::NoiseModelFactorN; ~NoiseModelFactor3() override {} - /** Methods to retrieve keys. - * Similar to `ValueType`, you can probably do `return key<#>();` - */ - inline Key key1() const { return this->template key<1>(); } - inline Key key2() const { return this->template key<2>(); } - inline Key key3() const { return this->template key<3>(); } - private: /** Serialization function */ friend class boost::serialization::access; @@ -719,8 +720,12 @@ class GTSAM_DEPRECATED NoiseModelFactor3 }; // \class NoiseModelFactor3 /* ************************************************************************* */ -/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 - * with ValueType<1>. If your class is templated, use `this->template key<1>()` +/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1>() and X1 + * with ValueType<1>. + * If your class is templated AND you are trying to call `.key<1>()` or + * `ValueType<1>` inside your class, due to dependent types you need to do + * `this->template key<1>()` or `This::template ValueType<1>`. + * ~~~ * A convenient base class for creating your own NoiseModelFactor * with 4 variables. To derive from this class, implement evaluateError(). */ @@ -748,14 +753,6 @@ class GTSAM_DEPRECATED NoiseModelFactor4 using NoiseModelFactorN::NoiseModelFactorN; ~NoiseModelFactor4() override {} - /** Methods to retrieve keys. - * Similar to `ValueType`, you can probably do `return key<#>();` - */ - inline Key key1() const { return this->template key<1>(); } - inline Key key2() const { return this->template key<2>(); } - inline Key key3() const { return this->template key<3>(); } - inline Key key4() const { return this->template key<4>(); } - private: /** Serialization function */ friend class boost::serialization::access; @@ -767,8 +764,12 @@ class GTSAM_DEPRECATED NoiseModelFactor4 }; // \class NoiseModelFactor4 /* ************************************************************************* */ -/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 - * with ValueType<1>. If your class is templated, use `this->template key<1>()` +/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1>() and X1 + * with ValueType<1>. + * If your class is templated AND you are trying to call `.key<1>()` or + * `ValueType<1>` inside your class, due to dependent types you need to do + * `this->template key<1>()` or `This::template ValueType<1>`. + * ~~~ * A convenient base class for creating your own NoiseModelFactor * with 5 variables. To derive from this class, implement evaluateError(). */ @@ -798,15 +799,6 @@ class GTSAM_DEPRECATED NoiseModelFactor5 VALUE5>::NoiseModelFactorN; ~NoiseModelFactor5() override {} - /** Methods to retrieve keys. - * Similar to `ValueType`, you can probably do `return key<#>();` - */ - inline Key key1() const { return this->template key<1>(); } - inline Key key2() const { return this->template key<2>(); } - inline Key key3() const { return this->template key<3>(); } - inline Key key4() const { return this->template key<4>(); } - inline Key key5() const { return this->template key<5>(); } - private: /** Serialization function */ friend class boost::serialization::access; @@ -818,8 +810,12 @@ class GTSAM_DEPRECATED NoiseModelFactor5 }; // \class NoiseModelFactor5 /* ************************************************************************* */ -/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 - * with ValueType<1>. If your class is templated, use `this->template key<1>()` +/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1>() and X1 + * with ValueType<1>. + * If your class is templated AND you are trying to call `.key<1>()` or + * `ValueType<1>` inside your class, due to dependent types you need to do + * `this->template key<1>()` or `This::template ValueType<1>`. + * ~~~ * A convenient base class for creating your own NoiseModelFactor * with 6 variables. To derive from this class, implement evaluateError(). */ @@ -852,16 +848,6 @@ class GTSAM_DEPRECATED NoiseModelFactor6 VALUE6>::NoiseModelFactorN; ~NoiseModelFactor6() override {} - /** Methods to retrieve keys. - * Similar to `ValueType`, you can probably do `return key<#>();` - */ - inline Key key1() const { return this->template key<1>(); } - inline Key key2() const { return this->template key<2>(); } - inline Key key3() const { return this->template key<3>(); } - inline Key key4() const { return this->template key<4>(); } - inline Key key5() const { return this->template key<5>(); } - inline Key key6() const { return this->template key<6>(); } - private: /** Serialization function */ friend class boost::serialization::access;