AutoDiffCostFunction: use static_assert to check if the correct overload of the constructor is used.

Change-Id: Iad06843b858ac45e87c0458522657b2e2c55f4e8
This commit is contained in:
Christopher Wecht
2018-10-24 14:34:23 +02:00
committed by Sameer Agarwal
parent 928592c57a
commit 7b0ce1adc4
+6 -6
View File
@@ -156,9 +156,9 @@ class AutoDiffCostFunction : public SizedCostFunction<kNumResiduals, Ns...> {
// number of residuals ("kNumResiduals").
explicit AutoDiffCostFunction(CostFunctor* functor)
: functor_(functor) {
CHECK_NE(kNumResiduals, DYNAMIC)
<< "Can't run the fixed-size constructor if the "
<< "number of residuals is set to ceres::DYNAMIC.";
static_assert(kNumResiduals != DYNAMIC,
"Can't run the fixed-size constructor if the number of "
"residuals is set to ceres::DYNAMIC.");
}
// Takes ownership of functor. Ignores the template-provided
@@ -168,9 +168,9 @@ class AutoDiffCostFunction : public SizedCostFunction<kNumResiduals, Ns...> {
// numbers of residuals at runtime.
AutoDiffCostFunction(CostFunctor* functor, int num_residuals)
: functor_(functor) {
CHECK_EQ(kNumResiduals, DYNAMIC)
<< "Can't run the dynamic-size constructor if the "
<< "number of residuals is not ceres::DYNAMIC.";
static_assert(kNumResiduals == DYNAMIC,
"Can't run the dynamic-size constructor if the number of "
"residuals is not ceres::DYNAMIC.");
SizedCostFunction<kNumResiduals, Ns...>::set_num_residuals(num_residuals);
}