[{"id":37556,"web_url":"https://patchwork.libcamera.org/comment/37556/","msgid":"<aWTBSLkqkOsPywl1@zed>","date":"2026-01-12T09:39:54","subject":"Re: [PATCH v4 05/22] libcamera: base: cxx20: Add `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 Tue, Jan 06, 2026 at 05:57:37PM +0100, 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> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nDo you think we can switch to c++20 and then re-apply the series on\ntop to remove these patches ?\n\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 1f4caf56f..d47168a70 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> +\tstatic_assert(std::is_unsigned_v<T>);\n> +\n> +\treturn x != 0 && (x & (x - 1)) == 0;\n> +}\n> +\n>  } /* namespace libcamera::internal::cxx20 */\n> --\n> 2.52.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 BC6BCBE08B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 12 Jan 2026 09:39:59 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6577561FA0;\n\tMon, 12 Jan 2026 10:39:59 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A3BE261FB9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Jan 2026 10:39:57 +0100 (CET)","from ideasonboard.com (net-93-65-100-155.cust.vodafonedsl.it\n\t[93.65.100.155])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 7B2712E0;\n\tMon, 12 Jan 2026 10:39:32 +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=\"lBXni0Qj\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1768210772;\n\tbh=VYXbgnLpoX17RwNgV+fVMuB5439aXijHSWO3yZG33nA=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=lBXni0Qjga9AzhPCNdpv8bdEr0P6GMArfcVKEr9Vcnn3JxeiYU6AxQoeZmNEjhbwm\n\txvGRCrLeuh94x2KRX3zzz64U12hp8G6qnNA5isC+4m9edtDJVIG3NClLUXbVeb4FJd\n\tdda/LUS3yGCmTTFayVCBDH9p0n305rb75j3DoYvE=","Date":"Mon, 12 Jan 2026 10:39:54 +0100","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, \n\tPaul Elder <paul.elder@ideasonboard.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>","Subject":"Re: [PATCH v4 05/22] libcamera: base: cxx20: Add `has_single_bit()`","Message-ID":"<aWTBSLkqkOsPywl1@zed>","References":"<20260106165754.1759831-1-barnabas.pocze@ideasonboard.com>\n\t<20260106165754.1759831-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":"<20260106165754.1759831-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>"}}]