From patchwork Thu Apr 3 15:49:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 23117 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 4AE4FC327D for ; Thu, 3 Apr 2025 15:49:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 01136689A1; Thu, 3 Apr 2025 17:49:40 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="XnT7DVGe"; 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 0310C68994 for ; Thu, 3 Apr 2025 17:49:38 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:6d9d:9854:3fc1:4bb2]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4C71D8FA; Thu, 3 Apr 2025 17:47:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1743695264; bh=wqVFTWlEEvkd8wBvHVZ2TIAwLhLy8s/Y2fDw4vYnFcA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XnT7DVGe4fTQ/rhS9ZTBYLk8Oyqa4V8YnDqI6u7iXX1pnB4qIkLz87/JQzrTp+nOJ RUtpJzFRXQinxPSnspnFcOXLmnPVQpUpsX40WxsprMYKTRXE7bw61souPQAF8g3+99 nRZoqJqgKJsOwCiiwQmP0Qv89NziZd+0SJClMMPQ= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , Laurent Pinchart Subject: [PATCH v3 01/16] libcamera: matrix: Replace SFINAE with static_asserts Date: Thu, 3 Apr 2025 17:49:06 +0200 Message-ID: <20250403154925.382973-2-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250403154925.382973-1-stefan.klug@ideasonboard.com> References: <20250403154925.382973-1-stefan.klug@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" SFINAE is difficult to read and not needed in these cases. Replace it with static_asserts. The idea came from [1] where it is stated: "The use of enable_if seems misguided to me. SFINAE is useful for the situation where we consider multiple candidates for something (overloads or class template specializations) and try to choose the correct one, without causing compilation to fail." [1]: https://stackoverflow.com/questions/62109526/c-friend-template-that-use-sfinae Signed-off-by: Stefan Klug Reviewed-by: Laurent Pinchart --- Changes in v2: - Added this patch Changes in v3: - Left SFINAE in place for the operators as static asserts could cause issues there --- include/libcamera/internal/matrix.h | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/include/libcamera/internal/matrix.h b/include/libcamera/internal/matrix.h index a055e6926c94..b9c3d41ef855 100644 --- a/include/libcamera/internal/matrix.h +++ b/include/libcamera/internal/matrix.h @@ -19,14 +19,11 @@ namespace libcamera { LOG_DECLARE_CATEGORY(Matrix) -#ifndef __DOXYGEN__ -template> * = nullptr> -#else template -#endif /* __DOXYGEN__ */ class Matrix { + static_assert(std::is_arithmetic_v, "Matrix type must be arithmetic"); + public: Matrix() { @@ -123,16 +120,10 @@ Matrix operator*(const Matrix &m, T d) return d * m; } -#ifndef __DOXYGEN__ -template * = nullptr> -#else -template -#endif /* __DOXYGEN__ */ -Matrix operator*(const Matrix &m1, const Matrix &m2) +template +constexpr Matrix operator*(const Matrix &m1, const Matrix &m2) { + static_assert(C1 == R2, "Matrix dimensions must match for multiplication"); Matrix result; for (unsigned int i = 0; i < R1; i++) {