From patchwork Sun Jun 21 00:23:03 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 27006 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id DEE01C3305 for ; Sun, 21 Jun 2026 00:23:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 25FF0656E9; Sun, 21 Jun 2026 02:23:14 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="TDXV6XVW"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DC3C9656E5 for ; Sun, 21 Jun 2026 02:23:09 +0200 (CEST) Received: from killaraus.ideasonboard.com (2001-14ba-70f3-e800--a06.rev.dnainternet.fi [IPv6:2001:14ba:70f3:e800::a06]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 05975268; Sun, 21 Jun 2026 02:22:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1782001353; bh=MHe02q6CXE8PDIJbA2P3DGADl8LDSW7CvfPNOr4bwOY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TDXV6XVWm8lL7JQa6OJAun/P0zYGTednOxBGxaza6fVciQD36UM1Ka04S0N+xh8RY PG4y+qDBbjVwGenZMFMAhfKb2X9YHh7gjBTOuxbqTUCVIj1q3Ud+IgnkyU6uvUbQhq hVNxYtfzRESErehJkeA2ZU4QSneu1dks5x3/nz3U= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham Subject: [PATCH 2/4] libcamera: vector: Swap order of arguments to apply() Date: Sun, 21 Jun 2026 03:23:03 +0300 Message-ID: <20260621002305.3763752-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260621002305.3763752-1-laurent.pinchart@ideasonboard.com> References: <20260621002305.3763752-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The Vector class is lacking a clamp() function, which will take two scalar parameters. To support that, the apply() function will need to be converted to variable number of parameters. This will require passing the scalar parameter last, to make automatic template arguments deduction possible. In preparation for that change, swap the arguments to apply() to pass the operation before the scalar parameter last. Only one variant of apply() strictly requires this change, arguments to the three other functions are also swapped for consistency. Also for consistency, swap the template arguments as well. Signed-off-by: Laurent Pinchart --- include/libcamera/internal/vector.h | 56 ++++++++++++++--------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h index 04ba5d847b7d..256de1d1c53a 100644 --- a/include/libcamera/internal/vector.h +++ b/include/libcamera/internal/vector.h @@ -73,116 +73,116 @@ public: constexpr Vector operator+(const Vector &other) const { - return apply(*this, other, std::plus<>{}); + return apply(*this, std::plus<>{}, other); } constexpr Vector operator+(T scalar) const { - return apply(*this, scalar, std::plus<>{}); + return apply(*this, std::plus<>{}, scalar); } constexpr Vector operator-(const Vector &other) const { - return apply(*this, other, std::minus<>{}); + return apply(*this, std::minus<>{}, other); } constexpr Vector operator-(T scalar) const { - return apply(*this, scalar, std::minus<>{}); + return apply(*this, std::minus<>{}, scalar); } constexpr Vector operator*(const Vector &other) const { - return apply(*this, other, std::multiplies<>{}); + return apply(*this, std::multiplies<>{}, other); } constexpr Vector operator*(T scalar) const { - return apply(*this, scalar, std::multiplies<>{}); + return apply(*this, std::multiplies<>{}, scalar); } constexpr Vector operator/(const Vector &other) const { - return apply(*this, other, std::divides<>{}); + return apply(*this, std::divides<>{}, other); } constexpr Vector operator/(T scalar) const { - return apply(*this, scalar, std::divides<>{}); + return apply(*this, std::divides<>{}, scalar); } constexpr Vector operator>>(unsigned int shift) const { static_assert(std::is_integral_v, "Vector::operator>> requires an integer element type"); - return apply(*this, shift, [](T a, unsigned int b) { return a >> b; }); + return apply(*this, [](T a, unsigned int b) { return a >> b; }, shift); } Vector &operator+=(const Vector &other) { - return apply(other, [](T a, T b) { return a + b; }); + return apply([](T a, T b) { return a + b; }, other); } Vector &operator+=(T scalar) { - return apply(scalar, [](T a, T b) { return a + b; }); + return apply([](T a, T b) { return a + b; }, scalar); } Vector &operator-=(const Vector &other) { - return apply(other, [](T a, T b) { return a - b; }); + return apply([](T a, T b) { return a - b; }, other); } Vector &operator-=(T scalar) { - return apply(scalar, [](T a, T b) { return a - b; }); + return apply([](T a, T b) { return a - b; }, scalar); } Vector &operator*=(const Vector &other) { - return apply(other, [](T a, T b) { return a * b; }); + return apply([](T a, T b) { return a * b; }, other); } Vector &operator*=(T scalar) { - return apply(scalar, [](T a, T b) { return a * b; }); + return apply([](T a, T b) { return a * b; }, scalar); } Vector &operator/=(const Vector &other) { - return apply(other, [](T a, T b) { return a / b; }); + return apply([](T a, T b) { return a / b; }, other); } Vector &operator/=(T scalar) { - return apply(scalar, [](T a, T b) { return a / b; }); + return apply([](T a, T b) { return a / b; }, scalar); } Vector &operator>>=(unsigned int shift) { static_assert(std::is_integral_v, "Vector::operator>>= requires an integer element type"); - return apply(shift, [](T a, unsigned int b) { return a >> b; }); + return apply([](T a, unsigned int b) { return a >> b; }, shift); } constexpr Vector min(const Vector &other) const { - return apply(*this, other, [](T a, T b) { return std::min(a, b); }); + return apply(*this, [](T a, T b) { return std::min(a, b); }, other); } constexpr Vector min(T scalar) const { - return apply(*this, scalar, [](T a, T b) { return std::min(a, b); }); + return apply(*this, [](T a, T b) { return std::min(a, b); }, scalar); } constexpr Vector max(const Vector &other) const { - return apply(*this, other, [](T a, T b) { return std::max(a, b); }); + return apply(*this, [](T a, T b) { return std::max(a, b); }, other); } constexpr Vector max(T scalar) const { - return apply(*this, scalar, [](T a, T b) -> T { return std::max(a, b); }); + return apply(*this, [](T a, T b) -> T { return std::max(a, b); }, scalar); } constexpr T dot(const Vector &other) const @@ -264,7 +264,7 @@ public: private: template - static constexpr Vector apply(const Vector &lhs, const Vector &rhs, BinaryOp op) + static constexpr Vector apply(const Vector &lhs, BinaryOp op, const Vector &rhs) { Vector result; std::transform(lhs.data_.begin(), lhs.data_.end(), @@ -274,8 +274,8 @@ private: return result; } - template - static constexpr Vector apply(const Vector &lhs, U rhs, BinaryOp op) + template + static constexpr Vector apply(const Vector &lhs, BinaryOp op, U rhs) { Vector result; std::transform(lhs.data_.begin(), lhs.data_.end(), @@ -286,7 +286,7 @@ private: } template - Vector &apply(const Vector &other, BinaryOp op) + Vector &apply(BinaryOp op, const Vector &other) { auto itOther = other.data_.begin(); std::for_each(data_.begin(), data_.end(), @@ -295,8 +295,8 @@ private: return *this; } - template - Vector &apply(U scalar, BinaryOp op) + template + Vector &apply(BinaryOp op, U scalar) { std::for_each(data_.begin(), data_.end(), [&op, scalar](T &v) { v = op(v, scalar); });