[{"id":34096,"web_url":"https://patchwork.libcamera.org/comment/34096/","msgid":"<174617152149.1586992.3244390573556787841@ping.linuxembedded.co.uk>","date":"2025-05-02T07:38:41","subject":"Re: [PATCH v3 01/16] libcamera: matrix: Replace SFINAE with\n\tstatic_asserts","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Stefan Klug (2025-04-03 16:49:06)\n> SFINAE is difficult to read and not needed in these cases. Replace it\n> with static_asserts. The idea came from [1] where it is stated:\n> \n> \"The use of enable_if seems misguided to me. SFINAE is useful for the\n> situation where we consider multiple candidates for something (overloads\n> or class template specializations) and try to choose the correct one,\n> without causing compilation to fail.\"\n> \n> [1]: https://stackoverflow.com/questions/62109526/c-friend-template-that-use-sfinae\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \n> ---\n> \n> Changes in v2:\n> - Added this patch\n> \n> Changes in v3:\n> - Left SFINAE in place for the operators as static asserts could cause\n>   issues there\n\nBarnabás, did this update resolve your concerns from v2?\n\n\n\n> ---\n>  include/libcamera/internal/matrix.h | 19 +++++--------------\n>  1 file changed, 5 insertions(+), 14 deletions(-)\n> \n> diff --git a/include/libcamera/internal/matrix.h b/include/libcamera/internal/matrix.h\n> index a055e6926c94..b9c3d41ef855 100644\n> --- a/include/libcamera/internal/matrix.h\n> +++ b/include/libcamera/internal/matrix.h\n> @@ -19,14 +19,11 @@ namespace libcamera {\n>  \n>  LOG_DECLARE_CATEGORY(Matrix)\n>  \n> -#ifndef __DOXYGEN__\n> -template<typename T, unsigned int Rows, unsigned int Cols,\n> -        std::enable_if_t<std::is_arithmetic_v<T>> * = nullptr>\n> -#else\n>  template<typename T, unsigned int Rows, unsigned int Cols>\n> -#endif /* __DOXYGEN__ */\n>  class Matrix\n>  {\n> +       static_assert(std::is_arithmetic_v<T>, \"Matrix type must be arithmetic\");\n> +\n>  public:\n>         Matrix()\n>         {\n> @@ -123,16 +120,10 @@ Matrix<U, Rows, Cols> operator*(const Matrix<U, Rows, Cols> &m, T d)\n>         return d * m;\n>  }\n>  \n> -#ifndef __DOXYGEN__\n> -template<typename T,\n> -        unsigned int R1, unsigned int C1,\n> -        unsigned int R2, unsigned int C2,\n> -        std::enable_if_t<C1 == R2> * = nullptr>\n> -#else\n> -template<typename T, unsigned int R1, unsigned int C1, unsigned int R2, unsigned in C2>\n> -#endif /* __DOXYGEN__ */\n> -Matrix<T, R1, C2> operator*(const Matrix<T, R1, C1> &m1, const Matrix<T, R2, C2> &m2)\n> +template<typename T, unsigned int R1, unsigned int C1, unsigned int R2, unsigned int C2>\n> +constexpr Matrix<T, R1, C2> operator*(const Matrix<T, R1, C1> &m1, const Matrix<T, R2, C2> &m2)\n>  {\n> +       static_assert(C1 == R2, \"Matrix dimensions must match for multiplication\");\n>         Matrix<T, R1, C2> result;\n>  \n>         for (unsigned int i = 0; i < R1; i++) {\n> -- \n> 2.43.0\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 8633BC327D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  2 May 2025 07:38:47 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8C85F68AD8;\n\tFri,  2 May 2025 09:38:46 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4EC1B68ACB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  2 May 2025 09:38:44 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 6A726353;\n\tFri,  2 May 2025 09:38:36 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"WFd1goXl\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1746171516;\n\tbh=fp6E4/FV77InC3k2eB/DhvkhybWRPrl7gzHXmMqnyTA=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=WFd1goXl8UDggdBAkTjhm0wSTooc7MIaZv5/2uSQdGpju3jbXk0zgpVNIj13RMFYM\n\ti7gaWbg+Nu4zu/HnpvCI1kM0sfIECgv2Xv3AB/+d4MNMY572YZ/YSqwWNo12r9/dzM\n\tJDBI5dEEb7KLZ5u1GLlJhKilJ7XZIBhIyjKF3iIU=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250403154925.382973-2-stefan.klug@ideasonboard.com>","References":"<20250403154925.382973-1-stefan.klug@ideasonboard.com>\n\t<20250403154925.382973-2-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v3 01/16] libcamera: matrix: Replace SFINAE with\n\tstatic_asserts","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Fri, 02 May 2025 08:38:41 +0100","Message-ID":"<174617152149.1586992.3244390573556787841@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":34118,"web_url":"https://patchwork.libcamera.org/comment/34118/","msgid":"<790ac02c-1cae-483e-8385-8bab1030f3a4@ideasonboard.com>","date":"2025-05-02T13:58:13","subject":"Re: [PATCH v3 01/16] libcamera: matrix: Replace SFINAE with\n\tstatic_asserts","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"Hi\n\n\n2025. 05. 02. 9:38 keltezéssel, Kieran Bingham írta:\n> Quoting Stefan Klug (2025-04-03 16:49:06)\n>> SFINAE is difficult to read and not needed in these cases. Replace it\n>> with static_asserts. The idea came from [1] where it is stated:\n>>\n>> \"The use of enable_if seems misguided to me. SFINAE is useful for the\n>> situation where we consider multiple candidates for something (overloads\n>> or class template specializations) and try to choose the correct one,\n>> without causing compilation to fail.\"\n>>\n>> [1]: https://stackoverflow.com/questions/62109526/c-friend-template-that-use-sfinae\n>>\n>> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n>> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n>>\n>> ---\n>>\n>> Changes in v2:\n>> - Added this patch\n>>\n>> Changes in v3:\n>> - Left SFINAE in place for the operators as static asserts could cause\n>>    issues there\n> \n> Barnabás, did this update resolve your concerns from v2?\n\nYes, although as I have mentioned, I think it was fine as is because it\nis an internal thing, and it can be changed arbitrarily if needed.\n\n\nRegards,\nBarnabás Pőcze\n\n> \n> \n> \n>> ---\n>>   include/libcamera/internal/matrix.h | 19 +++++--------------\n>>   1 file changed, 5 insertions(+), 14 deletions(-)\n>>\n>> diff --git a/include/libcamera/internal/matrix.h b/include/libcamera/internal/matrix.h\n>> index a055e6926c94..b9c3d41ef855 100644\n>> --- a/include/libcamera/internal/matrix.h\n>> +++ b/include/libcamera/internal/matrix.h\n>> @@ -19,14 +19,11 @@ namespace libcamera {\n>>   \n>>   LOG_DECLARE_CATEGORY(Matrix)\n>>   \n>> -#ifndef __DOXYGEN__\n>> -template<typename T, unsigned int Rows, unsigned int Cols,\n>> -        std::enable_if_t<std::is_arithmetic_v<T>> * = nullptr>\n>> -#else\n>>   template<typename T, unsigned int Rows, unsigned int Cols>\n>> -#endif /* __DOXYGEN__ */\n>>   class Matrix\n>>   {\n>> +       static_assert(std::is_arithmetic_v<T>, \"Matrix type must be arithmetic\");\n>> +\n>>   public:\n>>          Matrix()\n>>          {\n>> @@ -123,16 +120,10 @@ Matrix<U, Rows, Cols> operator*(const Matrix<U, Rows, Cols> &m, T d)\n>>          return d * m;\n>>   }\n>>   \n>> -#ifndef __DOXYGEN__\n>> -template<typename T,\n>> -        unsigned int R1, unsigned int C1,\n>> -        unsigned int R2, unsigned int C2,\n>> -        std::enable_if_t<C1 == R2> * = nullptr>\n>> -#else\n>> -template<typename T, unsigned int R1, unsigned int C1, unsigned int R2, unsigned in C2>\n>> -#endif /* __DOXYGEN__ */\n>> -Matrix<T, R1, C2> operator*(const Matrix<T, R1, C1> &m1, const Matrix<T, R2, C2> &m2)\n>> +template<typename T, unsigned int R1, unsigned int C1, unsigned int R2, unsigned int C2>\n>> +constexpr Matrix<T, R1, C2> operator*(const Matrix<T, R1, C1> &m1, const Matrix<T, R2, C2> &m2)\n>>   {\n>> +       static_assert(C1 == R2, \"Matrix dimensions must match for multiplication\");\n>>          Matrix<T, R1, C2> result;\n>>   \n>>          for (unsigned int i = 0; i < R1; i++) {\n>> -- \n>> 2.43.0\n>>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 95907C327D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  2 May 2025 13:58:19 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8D16968ADC;\n\tFri,  2 May 2025 15:58:18 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5B4BF68AD3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  2 May 2025 15:58:17 +0200 (CEST)","from [192.168.33.18] (185.221.143.50.nat.pool.zt.hu\n\t[185.221.143.50])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 32C61353;\n\tFri,  2 May 2025 15:58:09 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Kj65+UTQ\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1746194289;\n\tbh=7Nu+yvK/Ht+N5MMoMVYdoGLMPNoxaWHE0gY29SCT+HE=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=Kj65+UTQ6eiE+4nRc5LlSlIZfqDXBI3umULGlBTEwJ4E9TmUZ4CAdzvl4qJdPOPfu\n\t+qQC3yebsAM5KmNEgv1TlASdv5JYTwSTh2fBdYAmXkjslvrJM0yYoX1I51rUOceH2G\n\tQwkUxkFRzIMEjvgodCnX1jbpTgIzmfy7F42YFs1w=","Message-ID":"<790ac02c-1cae-483e-8385-8bab1030f3a4@ideasonboard.com>","Date":"Fri, 2 May 2025 15:58:13 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v3 01/16] libcamera: matrix: Replace SFINAE with\n\tstatic_asserts","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org,\n\tStefan Klug <stefan.klug@ideasonboard.com>","References":"<20250403154925.382973-1-stefan.klug@ideasonboard.com>\n\t<20250403154925.382973-2-stefan.klug@ideasonboard.com>\n\t<174617152149.1586992.3244390573556787841@ping.linuxembedded.co.uk>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<174617152149.1586992.3244390573556787841@ping.linuxembedded.co.uk>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":34127,"web_url":"https://patchwork.libcamera.org/comment/34127/","msgid":"<174629836225.2902011.10608325476465338505@ping.linuxembedded.co.uk>","date":"2025-05-03T18:52:42","subject":"Re: [PATCH v3 01/16] libcamera: matrix: Replace SFINAE with\n\tstatic_asserts","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Barnabás Pőcze (2025-05-02 14:58:13)\n> Hi\n> \n> \n> 2025. 05. 02. 9:38 keltezéssel, Kieran Bingham írta:\n> > Quoting Stefan Klug (2025-04-03 16:49:06)\n> >> SFINAE is difficult to read and not needed in these cases. Replace it\n> >> with static_asserts. The idea came from [1] where it is stated:\n> >>\n> >> \"The use of enable_if seems misguided to me. SFINAE is useful for the\n> >> situation where we consider multiple candidates for something (overloads\n> >> or class template specializations) and try to choose the correct one,\n> >> without causing compilation to fail.\"\n> >>\n> >> [1]: https://stackoverflow.com/questions/62109526/c-friend-template-that-use-sfinae\n> >>\n> >> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> >> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> >>\n> >> ---\n> >>\n> >> Changes in v2:\n> >> - Added this patch\n> >>\n> >> Changes in v3:\n> >> - Left SFINAE in place for the operators as static asserts could cause\n> >>    issues there\n> > \n> > Barnabás, did this update resolve your concerns from v2?\n> \n> Yes, although as I have mentioned, I think it was fine as is because it\n> is an internal thing, and it can be changed arbitrarily if needed.\n\nDoes that mean this patch can have your RB tag ?\n\n--\nKieran\n\n\n> \n> \n> Regards,\n> Barnabás Pőcze\n> \n> > \n> > \n> > \n> >> ---\n> >>   include/libcamera/internal/matrix.h | 19 +++++--------------\n> >>   1 file changed, 5 insertions(+), 14 deletions(-)\n> >>\n> >> diff --git a/include/libcamera/internal/matrix.h b/include/libcamera/internal/matrix.h\n> >> index a055e6926c94..b9c3d41ef855 100644\n> >> --- a/include/libcamera/internal/matrix.h\n> >> +++ b/include/libcamera/internal/matrix.h\n> >> @@ -19,14 +19,11 @@ namespace libcamera {\n> >>   \n> >>   LOG_DECLARE_CATEGORY(Matrix)\n> >>   \n> >> -#ifndef __DOXYGEN__\n> >> -template<typename T, unsigned int Rows, unsigned int Cols,\n> >> -        std::enable_if_t<std::is_arithmetic_v<T>> * = nullptr>\n> >> -#else\n> >>   template<typename T, unsigned int Rows, unsigned int Cols>\n> >> -#endif /* __DOXYGEN__ */\n> >>   class Matrix\n> >>   {\n> >> +       static_assert(std::is_arithmetic_v<T>, \"Matrix type must be arithmetic\");\n> >> +\n> >>   public:\n> >>          Matrix()\n> >>          {\n> >> @@ -123,16 +120,10 @@ Matrix<U, Rows, Cols> operator*(const Matrix<U, Rows, Cols> &m, T d)\n> >>          return d * m;\n> >>   }\n> >>   \n> >> -#ifndef __DOXYGEN__\n> >> -template<typename T,\n> >> -        unsigned int R1, unsigned int C1,\n> >> -        unsigned int R2, unsigned int C2,\n> >> -        std::enable_if_t<C1 == R2> * = nullptr>\n> >> -#else\n> >> -template<typename T, unsigned int R1, unsigned int C1, unsigned int R2, unsigned in C2>\n> >> -#endif /* __DOXYGEN__ */\n> >> -Matrix<T, R1, C2> operator*(const Matrix<T, R1, C1> &m1, const Matrix<T, R2, C2> &m2)\n> >> +template<typename T, unsigned int R1, unsigned int C1, unsigned int R2, unsigned int C2>\n> >> +constexpr Matrix<T, R1, C2> operator*(const Matrix<T, R1, C1> &m1, const Matrix<T, R2, C2> &m2)\n> >>   {\n> >> +       static_assert(C1 == R2, \"Matrix dimensions must match for multiplication\");\n> >>          Matrix<T, R1, C2> result;\n> >>   \n> >>          for (unsigned int i = 0; i < R1; i++) {\n> >> -- \n> >> 2.43.0\n> >>\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 51B92C3226\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat,  3 May 2025 18:52:47 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7189868B25;\n\tSat,  3 May 2025 20:52:46 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 57587617CB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat,  3 May 2025 20:52:45 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 6E12455;\n\tSat,  3 May 2025 20:52:36 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"bA3JKJ1w\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1746298356;\n\tbh=QLFZ0aqteNCiBtNxC3oTO4XAMay+NIZ2gv2P2XgVG3Y=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=bA3JKJ1wGAjSqk+FIE8F9tkFE9l0GlS+CnEu71FakXZzZYXoU0gvDPN/1zdBiGIIK\n\tLcwipRzsh5UVR4gN54bAKo03uEenExF0Rc8jzfXcpc1kVCNgKEaE3Fqs5FWQQuiMfT\n\tB28/nSvxcag4/p3qK9MWBTk4RwG8QzJhHPg+8zSM=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<790ac02c-1cae-483e-8385-8bab1030f3a4@ideasonboard.com>","References":"<20250403154925.382973-1-stefan.klug@ideasonboard.com>\n\t<20250403154925.382973-2-stefan.klug@ideasonboard.com>\n\t<174617152149.1586992.3244390573556787841@ping.linuxembedded.co.uk>\n\t<790ac02c-1cae-483e-8385-8bab1030f3a4@ideasonboard.com>","Subject":"Re: [PATCH v3 01/16] libcamera: matrix: Replace SFINAE with\n\tstatic_asserts","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org,\n\tStefan Klug <stefan.klug@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Date":"Sat, 03 May 2025 19:52:42 +0100","Message-ID":"<174629836225.2902011.10608325476465338505@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":34138,"web_url":"https://patchwork.libcamera.org/comment/34138/","msgid":"<aBt83iIiwwZ4p4ed@pyrite.rasen.tech>","date":"2025-05-07T15:31:42","subject":"Re: [PATCH v3 01/16] libcamera: matrix: Replace SFINAE with\n\tstatic_asserts","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"On Thu, Apr 03, 2025 at 05:49:06PM +0200, Stefan Klug wrote:\n> SFINAE is difficult to read and not needed in these cases. Replace it\n> with static_asserts. The idea came from [1] where it is stated:\n> \n> \"The use of enable_if seems misguided to me. SFINAE is useful for the\n> situation where we consider multiple candidates for something (overloads\n> or class template specializations) and try to choose the correct one,\n> without causing compilation to fail.\"\n> \n> [1]: https://stackoverflow.com/questions/62109526/c-friend-template-that-use-sfinae\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> \n> ---\n> \n> Changes in v2:\n> - Added this patch\n> \n> Changes in v3:\n> - Left SFINAE in place for the operators as static asserts could cause\n>   issues there\n> ---\n>  include/libcamera/internal/matrix.h | 19 +++++--------------\n>  1 file changed, 5 insertions(+), 14 deletions(-)\n> \n> diff --git a/include/libcamera/internal/matrix.h b/include/libcamera/internal/matrix.h\n> index a055e6926c94..b9c3d41ef855 100644\n> --- a/include/libcamera/internal/matrix.h\n> +++ b/include/libcamera/internal/matrix.h\n> @@ -19,14 +19,11 @@ namespace libcamera {\n>  \n>  LOG_DECLARE_CATEGORY(Matrix)\n>  \n> -#ifndef __DOXYGEN__\n> -template<typename T, unsigned int Rows, unsigned int Cols,\n> -\t std::enable_if_t<std::is_arithmetic_v<T>> * = nullptr>\n> -#else\n>  template<typename T, unsigned int Rows, unsigned int Cols>\n> -#endif /* __DOXYGEN__ */\n>  class Matrix\n>  {\n> +\tstatic_assert(std::is_arithmetic_v<T>, \"Matrix type must be arithmetic\");\n> +\n>  public:\n>  \tMatrix()\n>  \t{\n> @@ -123,16 +120,10 @@ Matrix<U, Rows, Cols> operator*(const Matrix<U, Rows, Cols> &m, T d)\n>  \treturn d * m;\n>  }\n>  \n> -#ifndef __DOXYGEN__\n> -template<typename T,\n> -\t unsigned int R1, unsigned int C1,\n> -\t unsigned int R2, unsigned int C2,\n> -\t std::enable_if_t<C1 == R2> * = nullptr>\n> -#else\n> -template<typename T, unsigned int R1, unsigned int C1, unsigned int R2, unsigned in C2>\n> -#endif /* __DOXYGEN__ */\n> -Matrix<T, R1, C2> operator*(const Matrix<T, R1, C1> &m1, const Matrix<T, R2, C2> &m2)\n> +template<typename T, unsigned int R1, unsigned int C1, unsigned int R2, unsigned int C2>\n> +constexpr Matrix<T, R1, C2> operator*(const Matrix<T, R1, C1> &m1, const Matrix<T, R2, C2> &m2)\n>  {\n> +\tstatic_assert(C1 == R2, \"Matrix dimensions must match for multiplication\");\n>  \tMatrix<T, R1, C2> result;\n>  \n>  \tfor (unsigned int i = 0; i < R1; i++) {\n> -- \n> 2.43.0\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 62FDAC3226\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  7 May 2025 15:31:48 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1B51A68B31;\n\tWed,  7 May 2025 17:31:48 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 15F3368AD8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  7 May 2025 17:31:47 +0200 (CEST)","from pyrite.rasen.tech (unknown\n\t[IPv6:2001:861:3a80:3300:4f2f:8c2c:b3ef:17d4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 91DD0C59;\n\tWed,  7 May 2025 17:31:35 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"G2v5wUXh\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1746631895;\n\tbh=4qEfszDTyVXAyR+Vn0A+4lf54SMSqpltckeO08Q7OVE=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=G2v5wUXhmBrp8DxnKi0La9nbaAbNmQ98/RUAkzBrLerjz6qW/GxNlVxzufhnQW+J2\n\t0rz3Z8OOt3ioEQl5lY0eC7CQFIntD8nMqu7cy8VM/6O2uKuiGhiHTbWY/S+z/eYlXS\n\tyjO2l1f5twynK1hEzse12dfW2jhWQnM2YnUsJrsg=","Date":"Wed, 7 May 2025 17:31:42 +0200","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>","Subject":"Re: [PATCH v3 01/16] libcamera: matrix: Replace SFINAE with\n\tstatic_asserts","Message-ID":"<aBt83iIiwwZ4p4ed@pyrite.rasen.tech>","References":"<20250403154925.382973-1-stefan.klug@ideasonboard.com>\n\t<20250403154925.382973-2-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20250403154925.382973-2-stefan.klug@ideasonboard.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":34159,"web_url":"https://patchwork.libcamera.org/comment/34159/","msgid":"<5b08e2ca-6fe2-4665-8f6f-8fa24caf994e@ideasonboard.com>","date":"2025-05-08T06:39:43","subject":"Re: [PATCH v3 01/16] libcamera: matrix: Replace SFINAE with\n\tstatic_asserts","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"2025. 05. 03. 20:52 keltezéssel, Kieran Bingham írta:\n> Quoting Barnabás Pőcze (2025-05-02 14:58:13)\n>> Hi\n>>\n>>\n>> 2025. 05. 02. 9:38 keltezéssel, Kieran Bingham írta:\n>>> Quoting Stefan Klug (2025-04-03 16:49:06)\n>>>> SFINAE is difficult to read and not needed in these cases. Replace it\n>>>> with static_asserts. The idea came from [1] where it is stated:\n>>>>\n>>>> \"The use of enable_if seems misguided to me. SFINAE is useful for the\n>>>> situation where we consider multiple candidates for something (overloads\n>>>> or class template specializations) and try to choose the correct one,\n>>>> without causing compilation to fail.\"\n>>>>\n>>>> [1]: https://stackoverflow.com/questions/62109526/c-friend-template-that-use-sfinae\n>>>>\n>>>> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n>>>> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n>>>>\n>>>> ---\n>>>>\n>>>> Changes in v2:\n>>>> - Added this patch\n>>>>\n>>>> Changes in v3:\n>>>> - Left SFINAE in place for the operators as static asserts could cause\n>>>>     issues there\n>>>\n>>> Barnabás, did this update resolve your concerns from v2?\n>>\n>> Yes, although as I have mentioned, I think it was fine as is because it\n>> is an internal thing, and it can be changed arbitrarily if needed.\n> \n> Does that mean this patch can have your RB tag ?\n\nReviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n\n\n> \n> --\n> Kieran\n> \n> \n>>\n>>\n>> Regards,\n>> Barnabás Pőcze\n>>\n>>>\n>>>\n>>>\n>>>> ---\n>>>>    include/libcamera/internal/matrix.h | 19 +++++--------------\n>>>>    1 file changed, 5 insertions(+), 14 deletions(-)\n>>>>\n>>>> diff --git a/include/libcamera/internal/matrix.h b/include/libcamera/internal/matrix.h\n>>>> index a055e6926c94..b9c3d41ef855 100644\n>>>> --- a/include/libcamera/internal/matrix.h\n>>>> +++ b/include/libcamera/internal/matrix.h\n>>>> @@ -19,14 +19,11 @@ namespace libcamera {\n>>>>    \n>>>>    LOG_DECLARE_CATEGORY(Matrix)\n>>>>    \n>>>> -#ifndef __DOXYGEN__\n>>>> -template<typename T, unsigned int Rows, unsigned int Cols,\n>>>> -        std::enable_if_t<std::is_arithmetic_v<T>> * = nullptr>\n>>>> -#else\n>>>>    template<typename T, unsigned int Rows, unsigned int Cols>\n>>>> -#endif /* __DOXYGEN__ */\n>>>>    class Matrix\n>>>>    {\n>>>> +       static_assert(std::is_arithmetic_v<T>, \"Matrix type must be arithmetic\");\n>>>> +\n>>>>    public:\n>>>>           Matrix()\n>>>>           {\n>>>> @@ -123,16 +120,10 @@ Matrix<U, Rows, Cols> operator*(const Matrix<U, Rows, Cols> &m, T d)\n>>>>           return d * m;\n>>>>    }\n>>>>    \n>>>> -#ifndef __DOXYGEN__\n>>>> -template<typename T,\n>>>> -        unsigned int R1, unsigned int C1,\n>>>> -        unsigned int R2, unsigned int C2,\n>>>> -        std::enable_if_t<C1 == R2> * = nullptr>\n>>>> -#else\n>>>> -template<typename T, unsigned int R1, unsigned int C1, unsigned int R2, unsigned in C2>\n>>>> -#endif /* __DOXYGEN__ */\n>>>> -Matrix<T, R1, C2> operator*(const Matrix<T, R1, C1> &m1, const Matrix<T, R2, C2> &m2)\n>>>> +template<typename T, unsigned int R1, unsigned int C1, unsigned int R2, unsigned int C2>\n>>>> +constexpr Matrix<T, R1, C2> operator*(const Matrix<T, R1, C1> &m1, const Matrix<T, R2, C2> &m2)\n>>>>    {\n>>>> +       static_assert(C1 == R2, \"Matrix dimensions must match for multiplication\");\n>>>>           Matrix<T, R1, C2> result;\n>>>>    \n>>>>           for (unsigned int i = 0; i < R1; i++) {\n>>>> -- \n>>>> 2.43.0\n>>>>\n>>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 02BE4C3226\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  8 May 2025 06:39:51 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 364FE68B45;\n\tThu,  8 May 2025 08:39:50 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0E2856175D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  8 May 2025 08:39:48 +0200 (CEST)","from [192.168.33.16] (185.221.141.56.nat.pool.zt.hu\n\t[185.221.141.56])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D2474446;\n\tThu,  8 May 2025 08:39:35 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"sqt2yEKR\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1746686376;\n\tbh=T4N+OmbwHxaVtlRsfHpSAq9JuLka3YNYtCBTADtDYhk=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=sqt2yEKR5TnofQLXKZlG5bBb0w1Di+cVg1XSWOCikokc5mGEvFJIafWLBXAZKAozz\n\twysZAfMp8DzOfyJ/U9qdJMVELFRMuqLeewNutPUvkAcsgf0UwWaxA04PpcTancRcW8\n\tkb7Cqk2QgU6u+MgrFW2g3WVESXt34QFLMGxKdB0Q=","Message-ID":"<5b08e2ca-6fe2-4665-8f6f-8fa24caf994e@ideasonboard.com>","Date":"Thu, 8 May 2025 08:39:43 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v3 01/16] libcamera: matrix: Replace SFINAE with\n\tstatic_asserts","To":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>","References":"<20250403154925.382973-1-stefan.klug@ideasonboard.com>\n\t<20250403154925.382973-2-stefan.klug@ideasonboard.com>\n\t<174617152149.1586992.3244390573556787841@ping.linuxembedded.co.uk>\n\t<790ac02c-1cae-483e-8385-8bab1030f3a4@ideasonboard.com>\n\t<174629836225.2902011.10608325476465338505@ping.linuxembedded.co.uk>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<174629836225.2902011.10608325476465338505@ping.linuxembedded.co.uk>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]