[{"id":35139,"web_url":"https://patchwork.libcamera.org/comment/35139/","msgid":"<zvjshvyayfrptjlcgxft5rs4ubneyfmtt6aciauhgsnqqkvaab@e2ujbbi7yn7m>","date":"2025-07-25T13:04:46","subject":"Re: [RFC PATCH v2 05/22] libcamera: base: cxx20: Add\n\t`has_single_bit()`","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Barnabás\n\nOn Mon, Jul 21, 2025 at 12:46:05PM +0200, Barnabás Pőcze wrote:\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> ---\n>  include/libcamera/base/details/cxx20.h | 10 ++++++++++\n>  1 file changed, 10 insertions(+)\n>\n> diff --git a/include/libcamera/base/details/cxx20.h b/include/libcamera/base/details/cxx20.h\n> index 2d26db53e..8bf45ff11 100644\n> --- a/include/libcamera/base/details/cxx20.h\n> +++ b/include/libcamera/base/details/cxx20.h\n> @@ -7,9 +7,19 @@\n>\n>  #pragma once\n>\n> +#include <type_traits>\n> +\n>  namespace libcamera::details::cxx20 {\n>\n>  template<typename T> struct type_identity { using type = T; };\n>  template<typename T> using type_identity_t = typename type_identity<T>::type;\n>\n> +template<typename T>\n> +constexpr bool has_single_bit(T x) noexcept\n> +{\n> +\tstatic_assert(std::is_unsigned_v<T>);\n\nI was wondering if a compile time assertion is better than restricting\nthe template substitution to unsigned int with std::enable_if<> but in\nthe end the result is the same...\n\n> +\n> +\treturn x != 0 && (x & (x - 1)) == 0;\n\ncppreference.com has a more \"compact\"\n\n        return x && !(x & (x - 1));\n\nUp to you!\n\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n\n> +}\n> +\n>  } /* namespace libcamera::details::cxx20 */\n> --\n> 2.50.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 AF0A1BDCC1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 25 Jul 2025 13:04:55 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 22B21690E3;\n\tFri, 25 Jul 2025 15:04:54 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2079B690A6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 25 Jul 2025 15:04:52 +0200 (CEST)","from ideasonboard.com (mob-5-90-139-29.net.vodafone.it\n\t[5.90.139.29])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A8BF9C66;\n\tFri, 25 Jul 2025 15:04:11 +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=\"rTco3u1Y\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1753448652;\n\tbh=FkLtInICyzjSFUODNpKYyvUesdatPW6B6C6wSIxzsYA=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=rTco3u1Yml+KiIiPFqGoGzbtl5uZUVYgdQejEQT/j/WT1YYBI4DqmmOf7VkHHW/9m\n\t50yi6vBvhWVS8uJXtiR9hAd8994zkksTr1aQm+gZhhBdbcCG2Z26oCFnW1z3UXHRDY\n\tsiXswwhaukPwV1Nt7zMpA/S4md3Gph+khdQQ3znI=","Date":"Fri, 25 Jul 2025 15:04:46 +0200","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [RFC PATCH v2 05/22] libcamera: base: cxx20: Add\n\t`has_single_bit()`","Message-ID":"<zvjshvyayfrptjlcgxft5rs4ubneyfmtt6aciauhgsnqqkvaab@e2ujbbi7yn7m>","References":"<20250721104622.1550908-1-barnabas.pocze@ideasonboard.com>\n\t<20250721104622.1550908-6-barnabas.pocze@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20250721104622.1550908-6-barnabas.pocze@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":35160,"web_url":"https://patchwork.libcamera.org/comment/35160/","msgid":"<20250727133609.GH27425@pendragon.ideasonboard.com>","date":"2025-07-27T13:36:09","subject":"Re: [RFC PATCH v2 05/22] libcamera: base: cxx20: Add\n\t`has_single_bit()`","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Fri, Jul 25, 2025 at 03:04:46PM +0200, Jacopo Mondi wrote:\n> Hi Barnabás\n> \n> On Mon, Jul 21, 2025 at 12:46:05PM +0200, Barnabás Pőcze wrote:\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> > ---\n> >  include/libcamera/base/details/cxx20.h | 10 ++++++++++\n> >  1 file changed, 10 insertions(+)\n> >\n> > diff --git a/include/libcamera/base/details/cxx20.h b/include/libcamera/base/details/cxx20.h\n> > index 2d26db53e..8bf45ff11 100644\n> > --- a/include/libcamera/base/details/cxx20.h\n> > +++ b/include/libcamera/base/details/cxx20.h\n> > @@ -7,9 +7,19 @@\n> >\n> >  #pragma once\n> >\n> > +#include <type_traits>\n> > +\n> >  namespace libcamera::details::cxx20 {\n> >\n> >  template<typename T> struct type_identity { using type = T; };\n> >  template<typename T> using type_identity_t = typename type_identity<T>::type;\n> >\n> > +template<typename T>\n> > +constexpr bool has_single_bit(T x) noexcept\n> > +{\n> > +\tstatic_assert(std::is_unsigned_v<T>);\n> \n> I was wondering if a compile time assertion is better than restricting\n> the template substitution to unsigned int with std::enable_if<> but in\n> the end the result is the same...\n\nWhen there are no other template candidates they need to be considered,\na static assertion will give better error messages.\n\nCan we add a std::is_integral check here to get closer to the C++20\nrequirements ?\n\n> > +\n> > +\treturn x != 0 && (x & (x - 1)) == 0;\n> \n> cppreference.com has a more \"compact\"\n> \n>         return x && !(x & (x - 1));\n> \n> Up to you!\n> \n> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> \n> > +}\n> > +\n> >  } /* namespace libcamera::details::cxx20 */","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 C85AFBDCC1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 27 Jul 2025 13:36:20 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A77AC69124;\n\tSun, 27 Jul 2025 15:36:19 +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 6AB5E69080\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 27 Jul 2025 15:36:16 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 97D0D4AD;\n\tSun, 27 Jul 2025 15:35:34 +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=\"jsrnmuoC\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1753623334;\n\tbh=crBXpKYq0NYgbDAUn+L6LwHiragFMlBymoLsZC6jRAs=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=jsrnmuoCLlQYcIq32JfmBGaLMktJ4wSq3XjgH3d82CDYf8sMwcFQr8DteVRzeqttd\n\tWJgt6WxSYcD8LePKI7sJkjM7zj0gUd2/nDuGEQ/n1RMrtueLU5iW6jb4BerGpmONTG\n\t3bnPXnFLJvPUnCAVNKMN6VNlIQ5j33dmsDLd8+zo=","Date":"Sun, 27 Jul 2025 16:36:09 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Subject":"Re: [RFC PATCH v2 05/22] libcamera: base: cxx20: Add\n\t`has_single_bit()`","Message-ID":"<20250727133609.GH27425@pendragon.ideasonboard.com>","References":"<20250721104622.1550908-1-barnabas.pocze@ideasonboard.com>\n\t<20250721104622.1550908-6-barnabas.pocze@ideasonboard.com>\n\t<zvjshvyayfrptjlcgxft5rs4ubneyfmtt6aciauhgsnqqkvaab@e2ujbbi7yn7m>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<zvjshvyayfrptjlcgxft5rs4ubneyfmtt6aciauhgsnqqkvaab@e2ujbbi7yn7m>","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":35162,"web_url":"https://patchwork.libcamera.org/comment/35162/","msgid":"<23a7d346-2b9f-4c1b-9624-07a75febcd7e@ideasonboard.com>","date":"2025-07-27T17:19:22","subject":"Re: [RFC PATCH v2 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":"Hi\n\n2025. 07. 27. 15:36 keltezéssel, Laurent Pinchart írta:\n> On Fri, Jul 25, 2025 at 03:04:46PM +0200, Jacopo Mondi wrote:\n>> Hi Barnabás\n>>\n>> On Mon, Jul 21, 2025 at 12:46:05PM +0200, Barnabás Pőcze wrote:\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>>> ---\n>>>   include/libcamera/base/details/cxx20.h | 10 ++++++++++\n>>>   1 file changed, 10 insertions(+)\n>>>\n>>> diff --git a/include/libcamera/base/details/cxx20.h b/include/libcamera/base/details/cxx20.h\n>>> index 2d26db53e..8bf45ff11 100644\n>>> --- a/include/libcamera/base/details/cxx20.h\n>>> +++ b/include/libcamera/base/details/cxx20.h\n>>> @@ -7,9 +7,19 @@\n>>>\n>>>   #pragma once\n>>>\n>>> +#include <type_traits>\n>>> +\n>>>   namespace libcamera::details::cxx20 {\n>>>\n>>>   template<typename T> struct type_identity { using type = T; };\n>>>   template<typename T> using type_identity_t = typename type_identity<T>::type;\n>>>\n>>> +template<typename T>\n>>> +constexpr bool has_single_bit(T x) noexcept\n>>> +{\n>>> +\tstatic_assert(std::is_unsigned_v<T>);\n>>\n>> I was wondering if a compile time assertion is better than restricting\n>> the template substitution to unsigned int with std::enable_if<> but in\n>> the end the result is the same...\n> \n> When there are no other template candidates they need to be considered,\n> a static assertion will give better error messages.\n> \n> Can we add a std::is_integral check here to get closer to the C++20\n> requirements ?\n\nC++20 defines it only for some unsigned types. Could you clarify why\n`std::is_integral` would be needed?\n\n\nRegards,\nBarnabás Pőcze\n\n\n> \n>>> +\n>>> +\treturn x != 0 && (x & (x - 1)) == 0;\n>>\n>> cppreference.com has a more \"compact\"\n>>\n>>          return x && !(x & (x - 1));\n>>\n>> Up to you!\n>>\n>> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n>>\n>>> +}\n>>> +\n>>>   } /* namespace libcamera::details::cxx20 */\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 0369EBDCC1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 27 Jul 2025 17:19:28 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 26FF169128;\n\tSun, 27 Jul 2025 19:19:28 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4FBB869080\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 27 Jul 2025 19:19:25 +0200 (CEST)","from [192.168.33.14] (185.221.140.39.nat.pool.zt.hu\n\t[185.221.140.39])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id CA0C64C9;\n\tSun, 27 Jul 2025 19:18:43 +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=\"rjnKny3x\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1753636723;\n\tbh=sF7bq2IILfVFZGNFpFXQpSKiWCFs7aRHL6yHx7xmwHQ=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=rjnKny3xaGEUm9fNJ62JZVMA88ck3/2o0Kw6tHEfV/yHWi2YCbts4xkRnCFhi5K3L\n\tysGEOAyqtoGUQDwpm93lh7jwzRr1V5l8O/MkrHpPU061hPt6qtS0E0aKG8nXrFUXSd\n\t9T+a4lm417fgr8xY4LE3wuETfuFm7lc09tcxdsfo=","Message-ID":"<23a7d346-2b9f-4c1b-9624-07a75febcd7e@ideasonboard.com>","Date":"Sun, 27 Jul 2025 19:19:22 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [RFC PATCH v2 05/22] libcamera: base: cxx20: Add\n\t`has_single_bit()`","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tJacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","References":"<20250721104622.1550908-1-barnabas.pocze@ideasonboard.com>\n\t<20250721104622.1550908-6-barnabas.pocze@ideasonboard.com>\n\t<zvjshvyayfrptjlcgxft5rs4ubneyfmtt6aciauhgsnqqkvaab@e2ujbbi7yn7m>\n\t<20250727133609.GH27425@pendragon.ideasonboard.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<20250727133609.GH27425@pendragon.ideasonboard.com>","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":35168,"web_url":"https://patchwork.libcamera.org/comment/35168/","msgid":"<20250727183846.GI30386@pendragon.ideasonboard.com>","date":"2025-07-27T18:38:46","subject":"Re: [RFC PATCH v2 05/22] libcamera: base: cxx20: Add\n\t`has_single_bit()`","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Sun, Jul 27, 2025 at 07:19:22PM +0200, Barnabás Pőcze wrote:\n> 2025. 07. 27. 15:36 keltezéssel, Laurent Pinchart írta:\n> > On Fri, Jul 25, 2025 at 03:04:46PM +0200, Jacopo Mondi wrote:\n> >> On Mon, Jul 21, 2025 at 12:46:05PM +0200, Barnabás Pőcze wrote:\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> >>> ---\n> >>>   include/libcamera/base/details/cxx20.h | 10 ++++++++++\n> >>>   1 file changed, 10 insertions(+)\n> >>>\n> >>> diff --git a/include/libcamera/base/details/cxx20.h b/include/libcamera/base/details/cxx20.h\n> >>> index 2d26db53e..8bf45ff11 100644\n> >>> --- a/include/libcamera/base/details/cxx20.h\n> >>> +++ b/include/libcamera/base/details/cxx20.h\n> >>> @@ -7,9 +7,19 @@\n> >>>\n> >>>   #pragma once\n> >>>\n> >>> +#include <type_traits>\n> >>> +\n> >>>   namespace libcamera::details::cxx20 {\n> >>>\n> >>>   template<typename T> struct type_identity { using type = T; };\n> >>>   template<typename T> using type_identity_t = typename type_identity<T>::type;\n> >>>\n> >>> +template<typename T>\n> >>> +constexpr bool has_single_bit(T x) noexcept\n> >>> +{\n> >>> +\tstatic_assert(std::is_unsigned_v<T>);\n> >>\n> >> I was wondering if a compile time assertion is better than restricting\n> >> the template substitution to unsigned int with std::enable_if<> but in\n> >> the end the result is the same...\n> > \n> > When there are no other template candidates they need to be considered,\n> > a static assertion will give better error messages.\n> > \n> > Can we add a std::is_integral check here to get closer to the C++20\n> > requirements ?\n> \n> C++20 defines it only for some unsigned types. Could you clarify why\n> `std::is_integral` would be needed?\n\nHmmm I suppose std::is_unsigned implies std::is_integral ?\n\nCould we match the C++20 requirements to avoid accidental use of this\nfunction that would not work with the C++20 version when we'll switch to\nthat standard ?\n\n> >>> +\n> >>> +\treturn x != 0 && (x & (x - 1)) == 0;\n> >>\n> >> cppreference.com has a more \"compact\"\n> >>\n> >>          return x && !(x & (x - 1));\n> >>\n> >> Up to you!\n> >>\n> >> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> >>\n> >>> +}\n> >>> +\n> >>>   } /* namespace libcamera::details::cxx20 */","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 534E8BDCC1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 27 Jul 2025 18:38:54 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E105A6912B;\n\tSun, 27 Jul 2025 20:38:53 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2E41669080\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 27 Jul 2025 20:38:53 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 9EAFD55A;\n\tSun, 27 Jul 2025 20:38:11 +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=\"am8T8xPs\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1753641491;\n\tbh=XlDCUghJBz5Rs2bNNh3gBuow49svg0QIHnbcmHtKnlY=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=am8T8xPs4epqdkTngATTVxP2NvmE0WHrkRClgVaY8HU0TN5Sow1sbwSniEx+YZchS\n\t1vf/Xbx8Qkb/XT8uEfHJn1skgowtsH7nfm/JTDajbx+QA6ZEc0wkfbO/MRHQzq+FoL\n\t8z/55BG0ITeG4CtL0T0d1ipc9+eFjBDG65VAzWTg=","Date":"Sun, 27 Jul 2025 21:38:46 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Subject":"Re: [RFC PATCH v2 05/22] libcamera: base: cxx20: Add\n\t`has_single_bit()`","Message-ID":"<20250727183846.GI30386@pendragon.ideasonboard.com>","References":"<20250721104622.1550908-1-barnabas.pocze@ideasonboard.com>\n\t<20250721104622.1550908-6-barnabas.pocze@ideasonboard.com>\n\t<zvjshvyayfrptjlcgxft5rs4ubneyfmtt6aciauhgsnqqkvaab@e2ujbbi7yn7m>\n\t<20250727133609.GH27425@pendragon.ideasonboard.com>\n\t<23a7d346-2b9f-4c1b-9624-07a75febcd7e@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<23a7d346-2b9f-4c1b-9624-07a75febcd7e@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":35169,"web_url":"https://patchwork.libcamera.org/comment/35169/","msgid":"<cacf146e-b51b-4bcc-9f7c-622b37d107f5@ideasonboard.com>","date":"2025-07-27T18:43:43","subject":"Re: [RFC PATCH v2 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. 07. 27. 20:38 keltezéssel, Laurent Pinchart írta:\n> On Sun, Jul 27, 2025 at 07:19:22PM +0200, Barnabás Pőcze wrote:\n>> 2025. 07. 27. 15:36 keltezéssel, Laurent Pinchart írta:\n>>> On Fri, Jul 25, 2025 at 03:04:46PM +0200, Jacopo Mondi wrote:\n>>>> On Mon, Jul 21, 2025 at 12:46:05PM +0200, Barnabás Pőcze wrote:\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>>>>> ---\n>>>>>    include/libcamera/base/details/cxx20.h | 10 ++++++++++\n>>>>>    1 file changed, 10 insertions(+)\n>>>>>\n>>>>> diff --git a/include/libcamera/base/details/cxx20.h b/include/libcamera/base/details/cxx20.h\n>>>>> index 2d26db53e..8bf45ff11 100644\n>>>>> --- a/include/libcamera/base/details/cxx20.h\n>>>>> +++ b/include/libcamera/base/details/cxx20.h\n>>>>> @@ -7,9 +7,19 @@\n>>>>>\n>>>>>    #pragma once\n>>>>>\n>>>>> +#include <type_traits>\n>>>>> +\n>>>>>    namespace libcamera::details::cxx20 {\n>>>>>\n>>>>>    template<typename T> struct type_identity { using type = T; };\n>>>>>    template<typename T> using type_identity_t = typename type_identity<T>::type;\n>>>>>\n>>>>> +template<typename T>\n>>>>> +constexpr bool has_single_bit(T x) noexcept\n>>>>> +{\n>>>>> +\tstatic_assert(std::is_unsigned_v<T>);\n>>>>\n>>>> I was wondering if a compile time assertion is better than restricting\n>>>> the template substitution to unsigned int with std::enable_if<> but in\n>>>> the end the result is the same...\n>>>\n>>> When there are no other template candidates they need to be considered,\n>>> a static assertion will give better error messages.\n>>>\n>>> Can we add a std::is_integral check here to get closer to the C++20\n>>> requirements ?\n>>\n>> C++20 defines it only for some unsigned types. Could you clarify why\n>> `std::is_integral` would be needed?\n> \n> Hmmm I suppose std::is_unsigned implies std::is_integral ?\n\nTechnically it doesn't, it only checks if it's an arithmetic type.\nBut I haven't see unsigned floats yet.\n\n\n> \n> Could we match the C++20 requirements to avoid accidental use of this\n> function that would not work with the C++20 version when we'll switch to\n> that standard ?\n\nI think `is_unsigned` gets us pretty close. Otherwise you'd need to do\na series of `std::is_same_v<...>` to match the C++20 requirements.\n\n\n> \n>>>>> +\n>>>>> +\treturn x != 0 && (x & (x - 1)) == 0;\n>>>>\n>>>> cppreference.com has a more \"compact\"\n>>>>\n>>>>           return x && !(x & (x - 1));\n>>>>\n>>>> Up to you!\n>>>>\n>>>> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n>>>>\n>>>>> +}\n>>>>> +\n>>>>>    } /* namespace libcamera::details::cxx20 */\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 221ADC3237\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 27 Jul 2025 18:43:51 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2272D69130;\n\tSun, 27 Jul 2025 20:43: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 C383269080\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 27 Jul 2025 20:43:47 +0200 (CEST)","from [192.168.33.14] (185.221.140.39.nat.pool.zt.hu\n\t[185.221.140.39])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 3060955A;\n\tSun, 27 Jul 2025 20:43:06 +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=\"wLJcNC58\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1753641786;\n\tbh=i5V6FZW0ePw9JNzX85ZiQAko+yGwPMsqavLR731p3RA=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=wLJcNC588afBHcR9wvsDpdkOQDl4rvzHN913QnlfzK8Dyb8HzUOHXMxmzfJoQhLij\n\tD6c1S4CUE9oO0/ZIWpYurzLDiIvcdKbbNuNHAFa6mm9YB9F07ltqODcaYHQI9dWN/w\n\tt4zZ6QF5WyxxnGn+c9oTG1jAyo12j2qYxF6szfdk=","Message-ID":"<cacf146e-b51b-4bcc-9f7c-622b37d107f5@ideasonboard.com>","Date":"Sun, 27 Jul 2025 20:43:43 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [RFC PATCH v2 05/22] libcamera: base: cxx20: Add\n\t`has_single_bit()`","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20250721104622.1550908-1-barnabas.pocze@ideasonboard.com>\n\t<20250721104622.1550908-6-barnabas.pocze@ideasonboard.com>\n\t<zvjshvyayfrptjlcgxft5rs4ubneyfmtt6aciauhgsnqqkvaab@e2ujbbi7yn7m>\n\t<20250727133609.GH27425@pendragon.ideasonboard.com>\n\t<23a7d346-2b9f-4c1b-9624-07a75febcd7e@ideasonboard.com>\n\t<20250727183846.GI30386@pendragon.ideasonboard.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<20250727183846.GI30386@pendragon.ideasonboard.com>","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":35919,"web_url":"https://patchwork.libcamera.org/comment/35919/","msgid":"<175827755906.2127323.17378364824881213982@neptunite.rasen.tech>","date":"2025-09-19T10:25:59","subject":"Re: [RFC PATCH v2 05/22] libcamera: base: cxx20: Add\n\t`has_single_bit()`","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"Quoting Barnabás Pőcze (2025-07-21 19:46:05)\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\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n>  include/libcamera/base/details/cxx20.h | 10 ++++++++++\n>  1 file changed, 10 insertions(+)\n> \n> diff --git a/include/libcamera/base/details/cxx20.h b/include/libcamera/base/details/cxx20.h\n> index 2d26db53e..8bf45ff11 100644\n> --- a/include/libcamera/base/details/cxx20.h\n> +++ b/include/libcamera/base/details/cxx20.h\n> @@ -7,9 +7,19 @@\n>  \n>  #pragma once\n>  \n> +#include <type_traits>\n> +\n>  namespace libcamera::details::cxx20 {\n>  \n>  template<typename T> struct type_identity { using type = T; };\n>  template<typename T> using type_identity_t = typename type_identity<T>::type;\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> +       return x != 0 && (x & (x - 1)) == 0;\n> +}\n> +\n>  } /* namespace libcamera::details::cxx20 */\n> -- \n> 2.50.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 71DDCBE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 19 Sep 2025 10:26:08 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EF5CB6B597;\n\tFri, 19 Sep 2025 12:26:07 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5724D62C35\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 19 Sep 2025 12:26:06 +0200 (CEST)","from neptunite.rasen.tech (unknown\n\t[IPv6:2404:7a81:160:2100:ae7e:60b0:e249:fbe5])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id AF208446;\n\tFri, 19 Sep 2025 12:24:45 +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=\"pmGnMJaz\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1758277486;\n\tbh=MFGixeTUDO4ITIlDq+CHdvs68GsiIZfXYwSOpvgAjHk=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=pmGnMJazfeLv9GihvYlSEXqnG+hH7JUfhrpiNOgC3xJnSpB9LsIZL5FEGCZGzOU6F\n\tqwem50vAIorfiq8tQrFCkiQjo3jGzvVuWgCgsdqYOlV246d4h+z05WQbhAlNoZVB+W\n\t+0d4BZRO5lwWMEvhqE1H3RZr6+70JB9lDSitdX3M=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250721104622.1550908-6-barnabas.pocze@ideasonboard.com>","References":"<20250721104622.1550908-1-barnabas.pocze@ideasonboard.com>\n\t<20250721104622.1550908-6-barnabas.pocze@ideasonboard.com>","Subject":"Re: [RFC PATCH v2 05/22] libcamera: base: cxx20: Add\n\t`has_single_bit()`","From":"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, 19 Sep 2025 19:25:59 +0900","Message-ID":"<175827755906.2127323.17378364824881213982@neptunite.rasen.tech>","User-Agent":"alot/0.0.0","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>"}}]