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})
release/4.3a0
Gerry Chen 2022-12-19 20:14:12 -05:00
parent b24511fb18
commit e8ddbbebff
No known key found for this signature in database
GPG Key ID: E9845092D3A57286
2 changed files with 7 additions and 1 deletions

View File

@ -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 <typename CONTAINER = std::initializer_list<Key>>
template <typename CONTAINER = std::initializer_list<Key>,
// check that CONTAINER is a container of Keys:
typename T = typename std::decay<
decltype(*std::declval<CONTAINER>().begin())>::type,
typename std::enable_if<std::is_convertible<T, Key>::value,
bool>::type = true>
NoiseModelFactorN(const SharedNoiseModel& noiseModel, CONTAINER keys)
: Base(noiseModel, keys) {
assert(keys.size() == N);

View File

@ -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));
}
/* ************************************************************************* */