Skip to content

Commit 399bbf1

Browse files
committed
Silence some compiler warnings
1 parent e3d0b5b commit 399bbf1

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

include/cppoptlib/function_expressions.h

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ struct ConstExpression : public FunctionInterface<TScalar, TMode, TDimension> {
5454

5555
TScalar c;
5656
explicit ConstExpression(TScalar c_) : c(c_) {}
57-
virtual TScalar operator()(const VectorType &x, VectorType *grad = nullptr,
58-
MatrixType *hess = nullptr) const override {
57+
virtual TScalar operator()(const VectorType& x, VectorType* grad = nullptr,
58+
MatrixType* hess = nullptr) const override {
5959
(void)x;
6060
if (grad) {
6161
*grad = VectorType::Zero(x.size());
@@ -108,9 +108,10 @@ struct AddExpression
108108

109109
F f;
110110
G g;
111-
AddExpression(const F &f_, const G &g_) : f(f_), g(g_) {}
112-
virtual ScalarType operator()(const VectorType &x, VectorType *grad = nullptr,
113-
MatrixType *hess = nullptr) const override {
111+
AddExpression(const F& f_, const G& g_) : f(f_), g(g_) {}
112+
virtual ScalarType operator()(
113+
const VectorType& x, [[maybe_unused]] VectorType* grad = nullptr,
114+
[[maybe_unused]] MatrixType* hess = nullptr) const override {
114115
if constexpr (TMode == DifferentiabilityMode::None) {
115116
return f(x) + g(x);
116117
} else if constexpr (TMode == DifferentiabilityMode::First) {
@@ -162,9 +163,9 @@ struct SubExpression
162163

163164
F f;
164165
G g;
165-
SubExpression(const F &f_, const G &g_) : f(f_), g(g_) {}
166-
virtual ScalarType operator()(const VectorType &x, VectorType *grad = nullptr,
167-
MatrixType *hess = nullptr) const override {
166+
SubExpression(const F& f_, const G& g_) : f(f_), g(g_) {}
167+
virtual ScalarType operator()(const VectorType& x, VectorType* grad = nullptr,
168+
MatrixType* hess = nullptr) const override {
168169
if constexpr (TMode == DifferentiabilityMode::None) {
169170
return f(x) - g(x);
170171
} else if constexpr (TMode == DifferentiabilityMode::First) {
@@ -210,11 +211,11 @@ struct MulExpression : public FunctionInterface<TScalar, TMode, F::Dimension> {
210211
using MatrixType = Eigen::Matrix<ScalarType, Dimension, Dimension>;
211212
static constexpr DifferentiabilityMode Differentiability = TMode;
212213

213-
F f;
214214
TScalar c;
215-
MulExpression(const TScalar &c_, const F &f_) : c(c_), f(f_) {}
216-
virtual ScalarType operator()(const VectorType &x, VectorType *grad = nullptr,
217-
MatrixType *hess = nullptr) const override {
215+
F f;
216+
MulExpression(const TScalar& c_, const F& f_) : c(c_), f(f_) {}
217+
virtual ScalarType operator()(const VectorType& x, VectorType* grad = nullptr,
218+
MatrixType* hess = nullptr) const override {
218219
if (c == TScalar(0)) {
219220
if (grad) {
220221
*grad = VectorType::Zero(x.size());
@@ -275,10 +276,10 @@ struct ProdExpression
275276
F f;
276277
G g;
277278

278-
ProdExpression(const F &f_, const G &g_) : f(f_), g(g_) {}
279+
ProdExpression(const F& f_, const G& g_) : f(f_), g(g_) {}
279280

280-
virtual ScalarType operator()(const VectorType &x, VectorType *grad = nullptr,
281-
MatrixType *hess = nullptr) const override {
281+
virtual ScalarType operator()(const VectorType& x, VectorType* grad = nullptr,
282+
MatrixType* hess = nullptr) const override {
282283
if constexpr (TMode == DifferentiabilityMode::None) {
283284
return f(x) * g(x);
284285
} else if constexpr (TMode == DifferentiabilityMode::First) {
@@ -326,10 +327,10 @@ struct MinZeroExpression
326327
F::Differentiability;
327328

328329
F f;
329-
explicit MinZeroExpression(const F &f_) : f(f_) {}
330+
explicit MinZeroExpression(const F& f_) : f(f_) {}
330331

331-
virtual ScalarType operator()(const VectorType &x, VectorType *grad = nullptr,
332-
MatrixType *hess = nullptr) const override {
332+
virtual ScalarType operator()(const VectorType& x, VectorType* grad = nullptr,
333+
MatrixType* hess = nullptr) const override {
333334
if constexpr (Differentiability == DifferentiabilityMode::None) {
334335
ScalarType val = f(x);
335336
// Use ConstExpression to return zero (with zero derivatives) if inactive.
@@ -369,10 +370,10 @@ struct MaxZeroExpression
369370
F::Differentiability;
370371

371372
F f;
372-
explicit MaxZeroExpression(const F &f_) : f(f_) {}
373+
explicit MaxZeroExpression(const F& f_) : f(f_) {}
373374

374-
virtual ScalarType operator()(const VectorType &x, VectorType *grad = nullptr,
375-
MatrixType *hess = nullptr) const override {
375+
virtual ScalarType operator()(const VectorType& x, VectorType* grad = nullptr,
376+
MatrixType* hess = nullptr) const override {
376377
if constexpr (Differentiability == DifferentiabilityMode::None) {
377378
ScalarType val = f(x);
378379
return (val <= 0)
@@ -402,7 +403,7 @@ struct MaxZeroExpression
402403
template <typename F, typename G,
403404
typename = std::void_t<decltype(F::Differentiability),
404405
decltype(G::Differentiability)>>
405-
auto operator+(const F &f, const G &g) {
406+
auto operator+(const F& f, const G& g) {
406407
static_assert(
407408
std::is_same<typename F::ScalarType, typename G::ScalarType>::value,
408409
"ScalarType must match in addition.");
@@ -417,7 +418,7 @@ auto operator+(const F &f, const G &g) {
417418
template <typename F, typename G,
418419
typename = std::void_t<decltype(F::Differentiability),
419420
decltype(G::Differentiability)>>
420-
auto operator-(const F &f, const G &g) {
421+
auto operator-(const F& f, const G& g) {
421422
static_assert(
422423
std::is_same<typename F::ScalarType, typename G::ScalarType>::value,
423424
"ScalarType must match in addition.");
@@ -430,15 +431,15 @@ auto operator-(const F &f, const G &g) {
430431

431432
// For multiplication (F * c and c * F).
432433
template <typename F>
433-
auto operator*(const F &f, const typename F::ScalarType &c)
434+
auto operator*(const F& f, const typename F::ScalarType& c)
434435
-> MulExpression<F, typename F::ScalarType, F::Differentiability> {
435436
using ScalarType = typename F::ScalarType;
436437
// Always return a MulExpression. Inside its operator() you can check if c==0.
437438
return MulExpression<F, ScalarType, F::Differentiability>(c, f);
438439
}
439440

440441
template <typename F>
441-
auto operator*(const typename F::ScalarType &c, const F &f)
442+
auto operator*(const typename F::ScalarType& c, const F& f)
442443
-> MulExpression<F, typename F::ScalarType, F::Differentiability> {
443444
using ScalarType = typename F::ScalarType;
444445
return MulExpression<F, ScalarType, F::Differentiability>(c, f);
@@ -449,7 +450,7 @@ auto operator*(const typename F::ScalarType &c, const F &f)
449450
template <typename F, typename G,
450451
typename = std::void_t<decltype(F::Differentiability),
451452
decltype(G::Differentiability)>>
452-
auto operator*(const F &f, const G &g) {
453+
auto operator*(const F& f, const G& g) {
453454
static_assert(
454455
std::is_same<typename F::ScalarType, typename G::ScalarType>::value,
455456
"ScalarType must match in addition.");
@@ -462,14 +463,14 @@ auto operator*(const F &f, const G &g) {
462463

463464
// Unary minus: returns a MulExpression representing (-1)*f.
464465
template <typename F>
465-
auto operator-(const F &f)
466+
auto operator-(const F& f)
466467
-> MulExpression<F, typename F::ScalarType, F::Differentiability> {
467468
return (-1) * f;
468469
}
469470

470471
// Overload for adding a constant scalar to a function (f + c).
471472
template <typename F>
472-
auto operator+(const F &f, const typename F::ScalarType &c) -> AddExpression<
473+
auto operator+(const F& f, const typename F::ScalarType& c) -> AddExpression<
473474
F,
474475
ConstExpression<typename F::ScalarType, F::Differentiability, F::Dimension>,
475476
F::Differentiability> {
@@ -482,7 +483,7 @@ auto operator+(const F &f, const typename F::ScalarType &c) -> AddExpression<
482483

483484
// Overload for adding a function to a constant scalar (c + f).
484485
template <typename F>
485-
auto operator+(const typename F::ScalarType &c, const F &f) -> AddExpression<
486+
auto operator+(const typename F::ScalarType& c, const F& f) -> AddExpression<
486487
ConstExpression<typename F::ScalarType, F::Differentiability, F::Dimension>,
487488
F, F::Differentiability> {
488489
using ScalarType = typename F::ScalarType;
@@ -494,7 +495,7 @@ auto operator+(const typename F::ScalarType &c, const F &f) -> AddExpression<
494495

495496
// Overload for subtracting a constant scalar from a function (f - c).
496497
template <typename F>
497-
auto operator-(const F &f, const typename F::ScalarType &c) {
498+
auto operator-(const F& f, const typename F::ScalarType& c) {
498499
using ScalarType = typename F::ScalarType;
499500
// Create a constant expression for the scalar.
500501
ConstExpression<ScalarType, F::Differentiability, F::Dimension> c_expr(c);
@@ -506,7 +507,7 @@ auto operator-(const F &f, const typename F::ScalarType &c) {
506507

507508
// Overload for subtracting a function from a constant scalar (c - f).
508509
template <typename F>
509-
auto operator-(const typename F::ScalarType &c, const F &f) {
510+
auto operator-(const typename F::ScalarType& c, const F& f) {
510511
using ScalarType = typename F::ScalarType;
511512
// Create a constant expression for the scalar.
512513
ConstExpression<ScalarType, F::Differentiability, F::Dimension> c_expr(c);

0 commit comments

Comments
 (0)