From e8ddbbebff6cb114fcfc986cd9b43cbfbdfabe29 Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Mon, 19 Dec 2022 20:14:12 -0500 Subject: [PATCH] Check type of CONTAINER constructor tparam This is a byproduct of the overload resolution problem when N=1, then it can be hard to differentiate between: NoiseModelFactorN(noise, key) NoiseModelFactorN(noise, {key}) --- gtsam/nonlinear/NonlinearFactor.h | 7 ++++++- tests/testNonlinearFactor.cpp | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index 33640f0b7..2f4b27d39 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -352,7 +352,12 @@ class NoiseModelFactorN : public NoiseModelFactor { * @param noiseModel Shared pointer to noise model. * @param keys A container of keys for the variables in this factor. */ - template > + template , + // check that CONTAINER is a container of Keys: + typename T = typename std::decay< + decltype(*std::declval().begin())>::type, + typename std::enable_if::value, + bool>::type = true> NoiseModelFactorN(const SharedNoiseModel& noiseModel, CONTAINER keys) : Base(noiseModel, keys) { assert(keys.size() == N); diff --git a/tests/testNonlinearFactor.cpp b/tests/testNonlinearFactor.cpp index 349e2cd86..9c4b4cff1 100644 --- a/tests/testNonlinearFactor.cpp +++ b/tests/testNonlinearFactor.cpp @@ -376,6 +376,7 @@ TEST(NonlinearFactor, NoiseModelFactor1) { // Test constructors TestFactor1 tf2(noiseModel::Unit::Create(1), L(1)); TestFactor1 tf3(noiseModel::Unit::Create(1), {L(1)}); + TestFactor1 tf4(noiseModel::Unit::Create(1), gtsam::Symbol('L', 1)); } /* ************************************************************************* */