diff --git a/examples/libmv_bundle_adjuster.cc b/examples/libmv_bundle_adjuster.cc index 2ab7d0def..be936780f 100644 --- a/examples/libmv_bundle_adjuster.cc +++ b/examples/libmv_bundle_adjuster.cc @@ -307,8 +307,8 @@ class EndianAwareFileReader { return value; } private: - static const long int kLittleEndian = 0x03020100ul; - static const long int kBigEndian = 0x00010203ul; + static constexpr long int kLittleEndian = 0x03020100ul; + static constexpr long int kBigEndian = 0x00010203ul; // Switch endian type between big to little. template diff --git a/examples/more_garbow_hillstrom.cc b/examples/more_garbow_hillstrom.cc index 87713a00f..0dc8fbfb4 100644 --- a/examples/more_garbow_hillstrom.cc +++ b/examples/more_garbow_hillstrom.cc @@ -80,7 +80,7 @@ static void SetNumericDiffOptions(ceres::NumericDiffOptions* options) { #define BEGIN_MGH_PROBLEM(name, num_parameters, num_residuals) \ struct name { \ - static const int kNumParameters = num_parameters; \ + static constexpr int kNumParameters = num_parameters; \ static const double initial_x[kNumParameters]; \ static const double lower_bounds[kNumParameters]; \ static const double upper_bounds[kNumParameters]; \ diff --git a/examples/robot_pose_mle.cc b/examples/robot_pose_mle.cc index 0076947f2..83c0903d1 100644 --- a/examples/robot_pose_mle.cc +++ b/examples/robot_pose_mle.cc @@ -160,7 +160,7 @@ DEFINE_double(range_stddev, 0.01, "The standard deviation of range readings of " "the robot."); // The stride length of the dynamic_autodiff_cost_function evaluator. -static const int kStride = 10; +static constexpr int kStride = 10; struct OdometryConstraint { typedef AutoDiffCostFunction OdometryCostFunction; diff --git a/internal/ceres/canonical_views_clustering.cc b/internal/ceres/canonical_views_clustering.cc index b2fd49ff7..e927e1f91 100644 --- a/internal/ceres/canonical_views_clustering.cc +++ b/internal/ceres/canonical_views_clustering.cc @@ -214,7 +214,7 @@ void CanonicalViewsClustering::ComputeClusterMembership( center_to_cluster_id[centers[i]] = i; } - static const int kInvalidClusterId = -1; + static constexpr int kInvalidClusterId = -1; const IntSet& views = graph_->vertices(); for (const auto& view : views) { diff --git a/internal/ceres/conditioned_cost_function_test.cc b/internal/ceres/conditioned_cost_function_test.cc index b0705f3b6..cd1550773 100644 --- a/internal/ceres/conditioned_cost_function_test.cc +++ b/internal/ceres/conditioned_cost_function_test.cc @@ -41,7 +41,7 @@ namespace ceres { namespace internal { // The size of the cost functions we build. -static const int kTestCostFunctionSize = 3; +static constexpr int kTestCostFunctionSize = 3; // A simple cost function: return ax + b. class LinearCostFunction : public CostFunction { diff --git a/internal/ceres/cubic_interpolation_test.cc b/internal/ceres/cubic_interpolation_test.cc index e1abb0fd3..4cf27ff85 100644 --- a/internal/ceres/cubic_interpolation_test.cc +++ b/internal/ceres/cubic_interpolation_test.cc @@ -38,7 +38,7 @@ namespace ceres { namespace internal { -static const double kTolerance = 1e-12; +static constexpr double kTolerance = 1e-12; TEST(Grid1D, OneDataDimension) { int x[] = {1, 2, 3}; @@ -255,8 +255,8 @@ class CubicInterpolatorTest : public ::testing::Test { } private: - static const int kNumSamples = 10; - static const int kNumTestSamples = 100; + static constexpr int kNumSamples = 10; + static constexpr int kNumTestSamples = 100; std::unique_ptr values_; }; @@ -375,10 +375,10 @@ class BiCubicInterpolatorTest : public ::testing::Test { Eigen::Matrix3d coeff_; - static const int kNumRows = 10; - static const int kNumCols = 10; - static const int kNumRowSamples = 100; - static const int kNumColSamples = 100; + static constexpr int kNumRows = 10; + static constexpr int kNumCols = 10; + static constexpr int kNumRowSamples = 100; + static constexpr int kNumColSamples = 100; std::unique_ptr values_; }; diff --git a/internal/ceres/invert_psd_matrix_test.cc b/internal/ceres/invert_psd_matrix_test.cc index 9ca38e399..279eeab27 100644 --- a/internal/ceres/invert_psd_matrix_test.cc +++ b/internal/ceres/invert_psd_matrix_test.cc @@ -36,8 +36,8 @@ namespace ceres { namespace internal { -static const bool kFullRank = true; -static const bool kRankDeficient = false; +static constexpr bool kFullRank = true; +static constexpr bool kRankDeficient = false; template typename EigenTypes::Matrix RandomPSDMatrixWithEigenValues( diff --git a/internal/ceres/loss_function.cc b/internal/ceres/loss_function.cc index 5963d4817..2c21a7377 100644 --- a/internal/ceres/loss_function.cc +++ b/internal/ceres/loss_function.cc @@ -102,7 +102,9 @@ void TolerantLoss::Evaluate(double s, double rho[3]) const { // large, it will overflow. Since numerically 1 + e^x == e^x when the // x is greater than about ln(2^53) for doubles, beyond this threshold // we substitute x for ln(1 + e^x) as a numerically equivalent approximation. - static const double kLog2Pow53 = 36.7; // ln(MathLimits::kEpsilon). + + // ln(MathLimits::kEpsilon). + static constexpr double kLog2Pow53 = 36.7; if (x > kLog2Pow53) { rho[0] = s - a_ - c_; rho[1] = 1.0; diff --git a/internal/ceres/numeric_diff_test_utils.h b/internal/ceres/numeric_diff_test_utils.h index 0eddebbc0..33497d9ce 100644 --- a/internal/ceres/numeric_diff_test_utils.h +++ b/internal/ceres/numeric_diff_test_utils.h @@ -39,10 +39,10 @@ namespace ceres { namespace internal { // Noise factor for randomized cost function. -static const double kNoiseFactor = 0.01; +static constexpr double kNoiseFactor = 0.01; // Default random seed for randomized cost function. -static const unsigned int kRandomSeed = 1234; +static constexpr unsigned int kRandomSeed = 1234; // y1 = x1'x2 -> dy1/dx1 = x2, dy1/dx2 = x1 // y2 = (x1'x2)^2 -> dy2/dx1 = 2 * x2 * (x1'x2), dy2/dx2 = 2 * x1 * (x1'x2) diff --git a/internal/ceres/rotation_test.cc b/internal/ceres/rotation_test.cc index 197495fe9..6a06632b4 100644 --- a/internal/ceres/rotation_test.cc +++ b/internal/ceres/rotation_test.cc @@ -334,7 +334,7 @@ TEST(Rotation, QuaternionToAngleAxisAngleIsLessThanPi) { EXPECT_LE(angle, kPi); } -static const int kNumTrials = 10000; +static constexpr int kNumTrials = 10000; // Takes a bunch of random axis/angle values, converts them to quaternions, // and back again. @@ -475,7 +475,7 @@ TEST(Rotation, NearPiAngleAxisRoundTrip) { TEST(Rotation, AtPiAngleAxisRoundTrip) { // A rotation of kPi about the X axis; - static const double kMatrix[3][3] = { + static constexpr double kMatrix[3][3] = { {1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, -1.0} diff --git a/internal/ceres/visibility.cc b/internal/ceres/visibility.cc index 72a1c337e..0981eeddc 100644 --- a/internal/ceres/visibility.cc +++ b/internal/ceres/visibility.cc @@ -125,7 +125,7 @@ WeightedGraph* CreateSchurComplementGraph( // Add vertices and initialize the pairs for self edges so that self // edges are guaranteed. This is needed for the Canonical views // algorithm to work correctly. - static const double kSelfEdgeWeight = 1.0; + static constexpr double kSelfEdgeWeight = 1.0; for (int i = 0; i < visibility.size(); ++i) { graph->AddVertex(i); graph->AddEdge(i, i, kSelfEdgeWeight); diff --git a/internal/ceres/visibility_based_preconditioner.cc b/internal/ceres/visibility_based_preconditioner.cc index 2b60facae..3372e82d1 100644 --- a/internal/ceres/visibility_based_preconditioner.cc +++ b/internal/ceres/visibility_based_preconditioner.cc @@ -65,9 +65,9 @@ using std::vector; // // This will require some more work on the clustering algorithm and // possibly some more refactoring of the code. -static const double kCanonicalViewsSizePenaltyWeight = 3.0; -static const double kCanonicalViewsSimilarityPenaltyWeight = 0.0; -static const double kSingleLinkageMinSimilarity = 0.9; +static constexpr double kCanonicalViewsSizePenaltyWeight = 3.0; +static constexpr double kCanonicalViewsSimilarityPenaltyWeight = 0.0; +static constexpr double kSingleLinkageMinSimilarity = 0.9; VisibilityBasedPreconditioner::VisibilityBasedPreconditioner( const CompressedRowBlockStructure& bs,