From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH v4 15/16] Allow the use of C++20 std::span in gdbsupport/span.h
Date: Wed, 18 Nov 2026 15:56:16 -0700 [thread overview]
Message-ID: <20261118-span-part-1-v4-15-5ecf901e570b@adacore.com> (raw)
In-Reply-To: <20261118-span-part-1-v4-0-5ecf901e570b@adacore.com>
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 | 62 ++++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 48 insertions(+), 14 deletions(-)
diff --git a/gdbsupport/span.h b/gdbsupport/span.h
index 67cb8fbb36e..54ae6eb0640 100644
--- a/gdbsupport/span.h
+++ b/gdbsupport/span.h
@@ -60,6 +60,33 @@
You can find unit tests covering the whole API in
unittests/span-selftests.c. */
+#if __cplusplus >= 202002L
+
+#include <span>
+
+namespace gdb {
+
+/* gdb::span. */
+template<typename T> using span = std::span<T>;
+
+namespace ranges
+{
+
+/* gdb::ranges::equal. */
+
+template<typename R1, typename R2>
+constexpr bool
+equal (R1 &&r1, R2 &&r2)
+{
+ return std::ranges::equal (r1, r2);
+}
+
+} /* namespace ranges */
+
+} /* namespace gdb */
+
+#else /* __cplusplus < 202002L */
+
namespace gdb {
template <typename T>
@@ -197,20 +224,6 @@ class span
size_type m_size;
};
-/* Copy the contents referenced by the span SRC to the span DEST.
-
- The two spans must have the same length. */
-
-template <typename U, typename T>
-void copy (gdb::span<U> src, gdb::span<T> 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 ());
-}
-
namespace ranges
{
@@ -234,6 +247,27 @@ equal (const gdb::span<T> &lhs, const gdb::span<T> &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 <typename U, typename T>
+void copy (gdb::span<U> src, gdb::span<T> 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
next prev parent reply other threads:[~2026-11-18 23:00 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 22:56 [PATCH v4 00/16] Rename gdb::array_view to gdb::span Tom Tromey
2026-11-18 22:56 ` [PATCH v4 01/16] Rename array_view files Tom Tromey
2026-11-18 22:56 ` [PATCH v4 02/16] Rename gdb::array_view to gdb::span Tom Tromey
2026-11-18 22:56 ` [PATCH v4 03/16] Rename gdb::make_array_view to gdb::make_span Tom Tromey
2026-11-18 22:56 ` [PATCH v4 04/16] Rename gdb_argv::as_array_view Tom Tromey
2026-11-18 22:56 ` [PATCH v4 05/16] Remove operator== and operator!= from gdb::span Tom Tromey
2026-11-18 22:56 ` [PATCH v4 06/16] Rename span::slice to span::subspan Tom Tromey
2026-11-18 22:56 ` [PATCH v4 07/16] Qualify calls to gdb::copy Tom Tromey
2026-11-18 22:56 ` [PATCH v4 08/16] Add single-argument overloads of process_options et al Tom Tromey
2026-11-18 22:56 ` [PATCH v4 09/16] Remove span from cli-option.c:build_help_option Tom Tromey
2026-11-18 22:56 ` [PATCH v4 10/16] gdb/unittests: use one static_assert per check in span-selftests.c Tom Tromey
2026-11-18 22:56 ` [PATCH v4 11/16] Don't use the single-argument gdb::span constructor Tom Tromey
2026-11-19 3:34 ` Simon Marchi
2026-11-19 3:42 ` Simon Marchi
2026-11-18 22:56 ` [PATCH v4 12/16] Don't turn rvalue reference into a span Tom Tromey
2026-11-19 3:50 ` Simon Marchi
2026-11-19 14:56 ` Tom Tromey
2026-11-18 22:56 ` [PATCH v4 13/16] Make gdb::span conform more closely to C++20 Tom Tromey
2026-11-18 22:56 ` [PATCH v4 14/16] Allow the use of C++20 std::ranges in gdbsupport/ranges.h Tom Tromey
2026-11-18 22:56 ` Tom Tromey [this message]
2026-11-19 3:52 ` [PATCH v4 15/16] Allow the use of C++20 std::span in gdbsupport/span.h Simon Marchi
2026-11-20 15:52 ` Jan Vrany
2026-11-20 20:15 ` Simon Marchi
2026-11-18 22:56 ` [PATCH v4 16/16] Move gdb::ranges::equal to gdbsupport/ranges.h Tom Tromey
2026-11-19 4:21 ` [PATCH v4 00/16] Rename gdb::array_view to gdb::span Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261118-span-part-1-v4-15-5ecf901e570b@adacore.com \
--to=tromey@adacore.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox