[{"id":36572,"web_url":"https://patchwork.libcamera.org/comment/36572/","msgid":"<176190974149.567526.17084877848226143713@ping.linuxembedded.co.uk>","date":"2025-10-31T11:22:21","subject":"Re: [RFC PATCH v3 05/22] libcamera: base: cxx20: Add\n\t`has_single_bit()`","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-10-30 16:57:59)\n> `has_single_bit()` checks if the given unsigned integer has a single\n> bit set, that is, whether the number is a power of two or not.\n> \n> Not all requirements of the C++20 standard are implemented.\n> \n> See https://en.cppreference.com/w/cpp/numeric/has_single_bit\n> \n> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n> ---\n>  include/libcamera/base/internal/cxx20.h | 16 ++++++++++++++++\n>  1 file changed, 16 insertions(+)\n> \n> diff --git a/include/libcamera/base/internal/cxx20.h b/include/libcamera/base/internal/cxx20.h\n> index 1f4caf56f8..d47168a70a 100644\n> --- a/include/libcamera/base/internal/cxx20.h\n> +++ b/include/libcamera/base/internal/cxx20.h\n> @@ -7,6 +7,8 @@\n>  \n>  #pragma once\n>  \n> +#include <type_traits>\n> +\n>  /**\n>   * \\internal\n>   * \\file cxx20.h\n> @@ -39,4 +41,18 @@ template<typename T> struct type_identity {\n>   */\n>  template<typename T> using type_identity_t = typename type_identity<T>::type;\n>  \n> +/**\n> + * \\internal\n> + * \\brief std::has_single_bit()\n> + *\n> + * Implementation of std::has_single_bit() for C++17.\n> + */\n> +template<typename T>\n> +constexpr bool has_single_bit(T x) noexcept\n> +{\n> +       static_assert(std::is_unsigned_v<T>);\n\nCan't this be forced to unsigned with an enable_if or such in the\ntemplate? But I guess compile time static assert is just the same and\nperhaps gives a nicer error so:\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> +\n> +       return x != 0 && (x & (x - 1)) == 0;\n> +}\n> +\n>  } /* namespace libcamera::internal::cxx20 */\n> -- \n> 2.51.1\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 C7042BE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 31 Oct 2025 11:22:26 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BCAE160970;\n\tFri, 31 Oct 2025 12:22:25 +0100 (CET)","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 43435600CC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 31 Oct 2025 12:22:24 +0100 (CET)","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 8EBD315D2;\n\tFri, 31 Oct 2025 12:20:33 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"S/pX9bF3\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1761909633;\n\tbh=XL0K0sY0GdlMYon2g1Ov/agEVsD0yPhoOFUzKe8c4ks=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=S/pX9bF3fBxiiN/YLpAmuFsx3QdCkGIy3awsuzK1pibbDUnjdGcQP4Kz26q6ff89T\n\tLm1ky4AbJ+KRsAiOloLxf9H9JIQg+46QU6YvyvChkdJfaVrLvP0xTmd12Wm/APkTsL\n\tOp+vYJtmudl3NDmhIwExoNY3WNAjdOsUysW1GaAU=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20251030165816.1095180-6-barnabas.pocze@ideasonboard.com>","References":"<20251030165816.1095180-1-barnabas.pocze@ideasonboard.com>\n\t<20251030165816.1095180-6-barnabas.pocze@ideasonboard.com>","Subject":"Re: [RFC PATCH v3 05/22] libcamera: base: cxx20: Add\n\t`has_single_bit()`","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Paul Elder <paul.elder@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Fri, 31 Oct 2025 11:22:21 +0000","Message-ID":"<176190974149.567526.17084877848226143713@ping.linuxembedded.co.uk>","User-Agent":"alot/0.9.1","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":36574,"web_url":"https://patchwork.libcamera.org/comment/36574/","msgid":"<bd2e11bf-a65b-4f4b-8cf7-eced39c8fff2@ideasonboard.com>","date":"2025-10-31T11:31:57","subject":"Re: [RFC PATCH v3 05/22] libcamera: base: cxx20: Add\n\t`has_single_bit()`","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"2025. 10. 31. 12:22 keltezéssel, Kieran Bingham írta:\n> Quoting Barnabás Pőcze (2025-10-30 16:57:59)\n>> `has_single_bit()` checks if the given unsigned integer has a single\n>> bit set, that is, whether the number is a power of two or not.\n>>\n>> Not all requirements of the C++20 standard are implemented.\n>>\n>> See https://en.cppreference.com/w/cpp/numeric/has_single_bit\n>>\n>> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n>> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n>> ---\n>>   include/libcamera/base/internal/cxx20.h | 16 ++++++++++++++++\n>>   1 file changed, 16 insertions(+)\n>>\n>> diff --git a/include/libcamera/base/internal/cxx20.h b/include/libcamera/base/internal/cxx20.h\n>> index 1f4caf56f8..d47168a70a 100644\n>> --- a/include/libcamera/base/internal/cxx20.h\n>> +++ b/include/libcamera/base/internal/cxx20.h\n>> @@ -7,6 +7,8 @@\n>>\n>>   #pragma once\n>>\n>> +#include <type_traits>\n>> +\n>>   /**\n>>    * \\internal\n>>    * \\file cxx20.h\n>> @@ -39,4 +41,18 @@ template<typename T> struct type_identity {\n>>    */\n>>   template<typename T> using type_identity_t = typename type_identity<T>::type;\n>>\n>> +/**\n>> + * \\internal\n>> + * \\brief std::has_single_bit()\n>> + *\n>> + * Implementation of std::has_single_bit() for C++17.\n>> + */\n>> +template<typename T>\n>> +constexpr bool has_single_bit(T x) noexcept\n>> +{\n>> +       static_assert(std::is_unsigned_v<T>);\n> \n> Can't this be forced to unsigned with an enable_if or such in the\n> template? But I guess compile time static assert is just the same and\n> perhaps gives a nicer error so:\n\nYes. But if there are no overloads, then I think a static_assert provides\nbetter error messages.\n\n\n> \n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n>> +\n>> +       return x != 0 && (x & (x - 1)) == 0;\n>> +}\n>> +\n>>   } /* namespace libcamera::internal::cxx20 */\n>> --\n>> 2.51.1\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 4DE0FBE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 31 Oct 2025 11:32:03 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 44BFF609A7;\n\tFri, 31 Oct 2025 12:32:02 +0100 (CET)","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 2D17B600CC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 31 Oct 2025 12:32:01 +0100 (CET)","from [192.168.33.30] (185.221.140.239.nat.pool.zt.hu\n\t[185.221.140.239])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5FDE115D2;\n\tFri, 31 Oct 2025 12:30:10 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"XBFANVtk\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1761910210;\n\tbh=/emutkkPRa7QVsJohSgcM5QgexjxHKM3kDntJTtGIRY=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=XBFANVtkoxG5VTPHp1j9h830tuu06D2LBBvZXWgQSIeEI41nPhNPbFJmCwfGqJ7tQ\n\tARlAyalhQsPQ1Hh3iq8t1MmF6HBVFeXzxGDF/LUZlhgy5A7uDSQSIZRohkLxccSzP4\n\t2tw+fvBGvkZYqnq99afD8uBMdgkWiGlQ2ppCiBoE=","Message-ID":"<bd2e11bf-a65b-4f4b-8cf7-eced39c8fff2@ideasonboard.com>","Date":"Fri, 31 Oct 2025 12:31:57 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [RFC PATCH v3 05/22] libcamera: base: cxx20: Add\n\t`has_single_bit()`","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Cc":"Paul Elder <paul.elder@ideasonboard.com>","References":"<20251030165816.1095180-1-barnabas.pocze@ideasonboard.com>\n\t<20251030165816.1095180-6-barnabas.pocze@ideasonboard.com>\n\t<8NmzOtdDRR5z2hfiOFA_EoGMwJ6rGz9ElP0S7GdO8imKjIn9SntD1ROFZ4hKcMU0WQz2TD4kOVva_xmqYcksoQ==@protonmail.internalid>\n\t<176190974149.567526.17084877848226143713@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":"<176190974149.567526.17084877848226143713@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":36599,"web_url":"https://patchwork.libcamera.org/comment/36599/","msgid":"<176202133838.3925733.9583554410526490642@ping.linuxembedded.co.uk>","date":"2025-11-01T18:22:18","subject":"Re: [RFC PATCH v3 05/22] libcamera: base: cxx20: Add\n\t`has_single_bit()`","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-10-31 11:31:57)\n> 2025. 10. 31. 12:22 keltezéssel, Kieran Bingham írta:\n> > Quoting Barnabás Pőcze (2025-10-30 16:57:59)\n> >> `has_single_bit()` checks if the given unsigned integer has a single\n> >> bit set, that is, whether the number is a power of two or not.\n> >>\n> >> Not all requirements of the C++20 standard are implemented.\n> >>\n> >> See https://en.cppreference.com/w/cpp/numeric/has_single_bit\n> >>\n> >> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n> >> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n> >> ---\n> >>   include/libcamera/base/internal/cxx20.h | 16 ++++++++++++++++\n> >>   1 file changed, 16 insertions(+)\n> >>\n> >> diff --git a/include/libcamera/base/internal/cxx20.h b/include/libcamera/base/internal/cxx20.h\n> >> index 1f4caf56f8..d47168a70a 100644\n> >> --- a/include/libcamera/base/internal/cxx20.h\n> >> +++ b/include/libcamera/base/internal/cxx20.h\n> >> @@ -7,6 +7,8 @@\n> >>\n> >>   #pragma once\n> >>\n> >> +#include <type_traits>\n> >> +\n> >>   /**\n> >>    * \\internal\n> >>    * \\file cxx20.h\n> >> @@ -39,4 +41,18 @@ template<typename T> struct type_identity {\n> >>    */\n> >>   template<typename T> using type_identity_t = typename type_identity<T>::type;\n> >>\n> >> +/**\n> >> + * \\internal\n> >> + * \\brief std::has_single_bit()\n> >> + *\n> >> + * Implementation of std::has_single_bit() for C++17.\n> >> + */\n> >> +template<typename T>\n> >> +constexpr bool has_single_bit(T x) noexcept\n> >> +{\n> >> +       static_assert(std::is_unsigned_v<T>);\n> > \n> > Can't this be forced to unsigned with an enable_if or such in the\n> > template? But I guess compile time static assert is just the same and\n> > perhaps gives a nicer error so:\n> \n> Yes. But if there are no overloads, then I think a static_assert provides\n> better error messages.\n> \n\nAgreed, this looks good to me.\n\n> \n> > \n> > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> > \n> >> +\n> >> +       return x != 0 && (x & (x - 1)) == 0;\n> >> +}\n> >> +\n> >>   } /* namespace libcamera::internal::cxx20 */\n> >> --\n> >> 2.51.1\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 D3753C3241\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat,  1 Nov 2025 18:22:23 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 474516086F;\n\tSat,  1 Nov 2025 19:22:23 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A333A606D5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat,  1 Nov 2025 19:22:21 +0100 (CET)","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 08806236;\n\tSat,  1 Nov 2025 19:20:29 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"foMIRmSd\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1762021230;\n\tbh=i8LYSNkZxige8bvuumqz2pe6m4fILpfkuCgNq1DuNfI=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=foMIRmSd4J6zwBGl7hSVie0j4usRosqX8NxbNUHRdtf+v55Pp9InOa83JQx4x/J7t\n\t7J9Q+G6qaLSmoFNcfNQcLUCy13cIooIcDhpD8Nm3o2mpuEEMehaSAuqVab85hhQ243\n\t35Z6kHHzDG7ABHF1m5jocquc4CbFWNi/O7VZZiME=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<bd2e11bf-a65b-4f4b-8cf7-eced39c8fff2@ideasonboard.com>","References":"<20251030165816.1095180-1-barnabas.pocze@ideasonboard.com>\n\t<20251030165816.1095180-6-barnabas.pocze@ideasonboard.com>\n\t<8NmzOtdDRR5z2hfiOFA_EoGMwJ6rGz9ElP0S7GdO8imKjIn9SntD1ROFZ4hKcMU0WQz2TD4kOVva_xmqYcksoQ==@protonmail.internalid>\n\t<176190974149.567526.17084877848226143713@ping.linuxembedded.co.uk>\n\t<bd2e11bf-a65b-4f4b-8cf7-eced39c8fff2@ideasonboard.com>","Subject":"Re: [RFC PATCH v3 05/22] libcamera: base: cxx20: Add\n\t`has_single_bit()`","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Paul Elder <paul.elder@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Sat, 01 Nov 2025 18:22:18 +0000","Message-ID":"<176202133838.3925733.9583554410526490642@ping.linuxembedded.co.uk>","User-Agent":"alot/0.9.1","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>"}}]