From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id iSYKJBKS9GoTUgIAWB0awg (envelope-from ) for ; Wed, 11 Nov 2026 11:04:34 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=Rr+A2vL/; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 8E5A8378002; Wed, 11 Nov 2026 11:04:34 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id E67D31E04F for ; Wed, 11 Nov 2026 11:04:33 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9F4D24B920AB for ; Wed, 11 Nov 2026 16:04:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9F4D24B920AB Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=Rr+A2vL/ Received: from mail-oo1-xc33.google.com (mail-oo1-xc33.google.com [IPv6:2607:f8b0:4864:20::c33]) by sourceware.org (Postfix) with ESMTPS id 214574BA2E16 for ; Wed, 11 Nov 2026 15:59:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 214574BA2E16 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 214574BA2E16 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1794412768; cv=none; b=kFpJ9Vf3G+zZq2ZjDoHK/tw4DCjFS0HspAW/tes9XRfLGelAZ1KLO+sYqtHLTCrPOo0AQgUxEYXc9rDFlLnt1V0cgtczBvcpAsCjP5McSuuYHntPRO2ao+90aKc0m6XzHSxbDSWCVUMzU++npjZBxUB9mddwLj0OjYHrJeqTPZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1794412768; c=relaxed/simple; bh=5qPjB2V2Q2nLNGz29aDRTLTrt4J7cyxyGRuGXfKZQzA=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=CfER7WTvvp6kOaZEDe4KezKrscOBVW1ox0yNLnot1F8VwxgYtIVo+VSRQl/J4Wv8jx/S2hjdHwP/1Qu4MMiGoXrtkgmPlM27YNhriL/6jtwY3zj3C5SoqS3MvoUiUS28U6diCSNXsIFIMciQXSlhfCeQT9m7NzjB5ApDvEUkhOo= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=Rr+A2vL/ DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 214574BA2E16 Received: by mail-oo1-xc33.google.com with SMTP id 006d021491bc7-6d290b10a35so1352055eaf.2 for ; Wed, 11 Nov 2026 07:59:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1794412767; x=1795017567; darn=sourceware.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=512C7UHwe5q09JDj9EhZulwIwYJOm5Mnsqfc/OZsp1Y=; b=Rr+A2vL/JwX+4gPb5/9jHOdmGaTC4vE63sasc0qwm/U2bqw7adHWRPx2Nvz2Cvh9cw pT+RVENUildLu1q2tPtLSqEaJ8Xql5rqVgOYU8a/tHapDLQSQYA1JCCNBkcFwi5fLZVK HILM89ly2mNq1UKBacSVgwSwD7JVDJ0gli3OekOQvzXvTqlZl1YY9/sreSd8a3aPYSTP Ul57GC4CylpgkNET3elk3mGviFLuQGlmi9+2vsZ4n/DslGNXr57X0pHTlTDaGpTZHdrl LAg3xOqbVPwznEuEHDvoIqbKjXdCpy6+JKrQ7aq0xKVc5r/r4SYJ5zqWLhQnQkkWgufm xVgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794412767; x=1795017567; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=512C7UHwe5q09JDj9EhZulwIwYJOm5Mnsqfc/OZsp1Y=; b=TSju0zlj/NCUkNdoMgySFE58/PndLuqI3R4aJ9hSXUgMiJMmGNHhAE34jkf9Q9drC/ uXGBOrJCxR9/pEFEBghCGCju6z15XR3/RFXvcDJhD7z3670sS1CY3+fjkqA5O8AiY8HZ /R8bp3Om5rmGLhH+AmZ4fEV3B9WrN87LSK8AepzeFAd1G8XaovW/xYzKtOOHBzhPi+xU lqjg7BxPmqtyE8eOLyY7874i79n3ATXIkJTShiqHBZohr8u/Iem06+8v/QUE+TWMNA+A FGLKABbDYZaXFWnDr83IN6R37bPIV55t6LH4fjm0kAg3r+pUGys09YJcYx7IVqi85msl 1spg== X-Gm-Message-State: APuU4Z/w/Z9MT+Xont6LD84B4QPHHYR9i1Z5rRiAnJjPfQiEdrtyo/Sg Ok475svNoefkr0pRZ32rkycl0MHiqVQ7MBmMROXIWnVK4/yrMraD8LZps5ec0rXCbJhvdin0uSO qLZfunw== X-Gm-Gg: AYBFou152fbJ3h85GG/084ZNBitA1+0ZV/OdU8c8L71dK0oLqC7dZE8vkbrvbd06zvy puriSE64g6m0lKMsGNbzqV119yQvHzYSLAf/j3FgCUfbts1ac8JMZVwl4W1iU8ntnkVspX8ok/J MTZ8IDPDHvl7Rj8I1KIxfbNNhNkR9jkr65Y1mlDQkCvqMOPu6EUqybIOtI22bKTnHvq+O7vHah2 RipS7KhvHr34LUhze7SD/6aP/aNItKFOvikLgq1l+Xzm39Rtzi28r6IP3kp6Zln3J0HYQ3tO60A uvIIH7gcuTeMktCchNPvRAt8n7NSGxYglkfXusptKkzPRzkP7zwm9DB61Y5sqjWpwJ+odYIqJsx 2F1H1tSySFX+AMKy8D9/FFFAUnIOx+cnK6IIvXqyNSFlHjj8ypDYly7cFxMy7/KYVQDJ8x4jxFv yV8XgbXTOHvC0Am8FaSBL9c9wzWUKMOjQZf/zNUEc1NsxlPIXs4wQsITmiDMrECRU1acvxJZGXF b2CbKZBdNJFTyiyyJmF0gP84uOcMTCZ/tskOyMBA7YSn9hwGlh4WbDLOXtJbm+UlML07Cxd6aDx si/pgHxd1O8cgRufYUswPuedxQDhsV//5PsrXOkTGH3RJmK2cGzDfnno0EkjAQ== X-Received: by 2002:a05:6820:60b:b0:70a:4053:52cf with SMTP id 006d021491bc7-71917612ef8mr1527519eaf.5.1794412767333; Wed, 11 Nov 2026 07:59:27 -0800 (PST) Received: from [192.168.0.26] (97-122-110-129.hlrn.qwest.net. [97.122.110.129]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-4ae2308e3ccsm3497521fac.15.2026.11.11.07.59.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Nov 2026 07:59:27 -0800 (PST) From: Tom Tromey Date: Wed, 11 Nov 2026 08:59:02 -0700 Subject: [PATCH v2 14/15] Allow the use of C++20 std::span in gdbsupport/span.h MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261111-span-part-1-v2-14-cd4e33a8a723@adacore.com> References: <20261111-span-part-1-v2-0-cd4e33a8a723@adacore.com> In-Reply-To: <20261111-span-part-1-v2-0-cd4e33a8a723@adacore.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.16.0 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org This patch changes gdbsupport/span.h to check __cplusplus and then to use std::span in this setup. Eventually, when gdb moves to C++20 (PR gdb/32660), this header can be greatly simplified and we can rewrite "gdb::span" to "std::span". Note that the header won't be really removable, because there are some utility functions here that will need to remain. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31422 --- gdbsupport/span.h | 61 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 14 deletions(-) diff --git a/gdbsupport/span.h b/gdbsupport/span.h index e3e3ddcbbd7..3759b05fb34 100644 --- a/gdbsupport/span.h +++ b/gdbsupport/span.h @@ -60,6 +60,32 @@ You can find unit tests covering the whole API in unittests/span-selftests.c. */ +#if __cplusplus >= 202002L + +#include + +namespace gdb { + +/* gdb::span. */ +template using span = std::span; + +/* gdb::ranges::equal. */ +namespace ranges +{ + +template +constexpr bool +equal (R1 &&r1, R2 &&r2) +{ + return std::ranges::equal (r1, r2); +} + +} /* namespace ranges */ + +} /* namespace gdb */ + +#else /* __cplusplus < 202002L */ + namespace gdb { template @@ -185,20 +211,6 @@ class span size_type m_size; }; -/* Copy the contents referenced by the array view SRC to the array view DEST. - - The two array views must have the same length. */ - -template -void copy (gdb::span src, gdb::span dest) -{ - gdb_assert (dest.size () == src.size ()); - if (dest.data () < src.data ()) - std::copy (src.begin (), src.end (), dest.begin ()); - else if (dest.data () > src.data ()) - std::copy_backward (src.begin (), src.end (), dest.end ()); -} - /* Compare LHS and RHS for (deep) equality. That is, whether LHS and RHS have the same sizes, and whether each pair of elements of LHS and RHS at the same position compares equal. */ @@ -222,6 +234,27 @@ equal (const gdb::span &lhs, const gdb::span &rhs) } /* namespace ranges */ +} /* namespace gdb */ + +#endif /* __cplusplus < 202002L */ + +namespace gdb +{ + +/* Copy the contents referenced by the array view SRC to the array view DEST. + + The two array views must have the same length. */ + +template +void copy (gdb::span src, gdb::span dest) +{ + gdb_assert (dest.size () == src.size ()); + if (dest.data () < src.data ()) + std::copy (src.begin (), src.end (), dest.begin ()); + else if (dest.data () > src.data ()) + std::copy_backward (src.begin (), src.end (), dest.end ()); +} + /* Create a span from a pointer to an array and an element count. -- 2.56.0