| Message ID | 20260621002305.3763752-4-laurent.pinchart@ideasonboard.com |
|---|---|
| State | Accepted |
| Headers | show |
| Series |
|
| Related | show |
Quoting Laurent Pinchart (2026-06-21 01:23:04) > In preparation for the addition of a clamp() function to the vector > class, extend the apply() function to support multiple scalar arguments. so I tried to look at using apply, fell down the rabbit hole of seeing I'd need to add a second instance and gave up (and posted what I had). So ... ok this could be cleaner indeed. If it gets through CI it's fine with me. Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > --- > include/libcamera/internal/vector.h | 14 +++++++------- > 1 file changed, 7 insertions(+), 7 deletions(-) > > diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h > index 256de1d1c53a..7c90d6542352 100644 > --- a/include/libcamera/internal/vector.h > +++ b/include/libcamera/internal/vector.h > @@ -274,13 +274,13 @@ private: > return result; > } > > - template<typename BinaryOp, typename U> > - static constexpr Vector apply(const Vector &lhs, BinaryOp op, U rhs) > + template<typename Op, typename... U> > + static constexpr Vector apply(const Vector &vector, Op op, U... scalar) > { > Vector result; > - std::transform(lhs.data_.begin(), lhs.data_.end(), > + std::transform(vector.data_.begin(), vector.data_.end(), > result.data_.begin(), > - [&op, rhs](T v) { return op(v, rhs); }); > + [&op, scalar...](T v) { return op(v, scalar...); }); > > return result; > } > @@ -295,11 +295,11 @@ private: > return *this; > } > > - template<typename BinaryOp, typename U> > - Vector &apply(BinaryOp op, U scalar) > + template<typename Op, typename... U> > + Vector &apply(Op op, U... scalar) > { > std::for_each(data_.begin(), data_.end(), > - [&op, scalar](T &v) { v = op(v, scalar); }); > + [&op, scalar...](T &v) { v = op(v, scalar...); }); > > return *this; > } > -- > Regards, > > Laurent Pinchart >
2026. 06. 21. 2:23 keltezéssel, Laurent Pinchart írta: > In preparation for the addition of a clamp() function to the vector > class, extend the apply() function to support multiple scalar arguments. > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > --- Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> > include/libcamera/internal/vector.h | 14 +++++++------- > 1 file changed, 7 insertions(+), 7 deletions(-) > > diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h > index 256de1d1c53a..7c90d6542352 100644 > --- a/include/libcamera/internal/vector.h > +++ b/include/libcamera/internal/vector.h > @@ -274,13 +274,13 @@ private: > return result; > } > > - template<typename BinaryOp, typename U> > - static constexpr Vector apply(const Vector &lhs, BinaryOp op, U rhs) > + template<typename Op, typename... U> > + static constexpr Vector apply(const Vector &vector, Op op, U... scalar) > { > Vector result; > - std::transform(lhs.data_.begin(), lhs.data_.end(), > + std::transform(vector.data_.begin(), vector.data_.end(), > result.data_.begin(), > - [&op, rhs](T v) { return op(v, rhs); }); > + [&op, scalar...](T v) { return op(v, scalar...); }); > > return result; > } > @@ -295,11 +295,11 @@ private: > return *this; > } > > - template<typename BinaryOp, typename U> > - Vector &apply(BinaryOp op, U scalar) > + template<typename Op, typename... U> > + Vector &apply(Op op, U... scalar) > { > std::for_each(data_.begin(), data_.end(), > - [&op, scalar](T &v) { v = op(v, scalar); }); > + [&op, scalar...](T &v) { v = op(v, scalar...); }); > > return *this; > }
diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h index 256de1d1c53a..7c90d6542352 100644 --- a/include/libcamera/internal/vector.h +++ b/include/libcamera/internal/vector.h @@ -274,13 +274,13 @@ private: return result; } - template<typename BinaryOp, typename U> - static constexpr Vector apply(const Vector &lhs, BinaryOp op, U rhs) + template<typename Op, typename... U> + static constexpr Vector apply(const Vector &vector, Op op, U... scalar) { Vector result; - std::transform(lhs.data_.begin(), lhs.data_.end(), + std::transform(vector.data_.begin(), vector.data_.end(), result.data_.begin(), - [&op, rhs](T v) { return op(v, rhs); }); + [&op, scalar...](T v) { return op(v, scalar...); }); return result; } @@ -295,11 +295,11 @@ private: return *this; } - template<typename BinaryOp, typename U> - Vector &apply(BinaryOp op, U scalar) + template<typename Op, typename... U> + Vector &apply(Op op, U... scalar) { std::for_each(data_.begin(), data_.end(), - [&op, scalar](T &v) { v = op(v, scalar); }); + [&op, scalar...](T &v) { v = op(v, scalar...); }); return *this; }
In preparation for the addition of a clamp() function to the vector class, extend the apply() function to support multiple scalar arguments. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- include/libcamera/internal/vector.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)