From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>,
Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH v3 17/17] Move gdb::ranges::equal to gdbsupport/ranges.h
Date: Tue, 17 Nov 2026 15:10:13 -0700 [thread overview]
Message-ID: <20261117-span-part-1-v3-17-40b8b11d2d8c@adacore.com> (raw)
In-Reply-To: <20261117-span-part-1-v3-0-40b8b11d2d8c@adacore.com>
This moves the gdb::ranges::equal function to gdbsupport/ranges.h.
When moving to C++20, this entire header can be removed.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32660
Approved-By: Simon Marchi <simon.marchi@efficios.com>
---
gdb/dwarf2/read-debug-names.c | 1 +
gdb/value.c | 1 +
gdbsupport/ranges.h | 27 +++++++++++++++++++++++++++
gdbsupport/span.h | 40 ----------------------------------------
4 files changed, 29 insertions(+), 40 deletions(-)
diff --git a/gdb/dwarf2/read-debug-names.c b/gdb/dwarf2/read-debug-names.c
index ca3b46fc9b1..ee35f06dde9 100644
--- a/gdb/dwarf2/read-debug-names.c
+++ b/gdb/dwarf2/read-debug-names.c
@@ -29,6 +29,7 @@
#include "read.h"
#include "stringify.h"
#include "extract-store-integer.h"
+#include "gdbsupport/ranges.h"
#include "gdbsupport/thread-pool.h"
#include "cli/cli-style.h"
diff --git a/gdb/value.c b/gdb/value.c
index 536eef3e00c..195f4bb5185 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -45,6 +45,7 @@
#include <vector>
#include "completer.h"
#include "gdbsupport/cleanups.h"
+#include "gdbsupport/ranges.h"
#include "gdbsupport/selftest.h"
#include "gdbsupport/span.h"
#include "cli/cli-style.h"
diff --git a/gdbsupport/ranges.h b/gdbsupport/ranges.h
index c89506da86d..e19bbb8224f 100644
--- a/gdbsupport/ranges.h
+++ b/gdbsupport/ranges.h
@@ -20,9 +20,36 @@
#include <algorithm>
+/* The 'equal' wrapper here only works on spans, so include this.
+ When moving to C++20, this will be removed -- in fact this entire
+ file should be removed. */
+#include "gdbsupport/span.h"
+
namespace gdb {
namespace ranges {
+/* 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. */
+
+template <typename T>
+bool
+equal (const gdb::span<T> &lhs, const gdb::span<T> &rhs)
+{
+#if __cplusplus >= 202002L
+ return std::ranges::equal (lhs, rhs);
+#else
+ if (lhs.size () != rhs.size ())
+ return false;
+
+ for (size_t i = 0; i < lhs.size (); i++)
+ if (!(lhs[i] == rhs[i]))
+ return false;
+
+ return true;
+#endif
+}
+
/* Replace all occurrences of a value in the provided range.
Note: this helper is a reimplementation of std::ranges::replace, only
diff --git a/gdbsupport/span.h b/gdbsupport/span.h
index cca1d88350b..9aa2a8b4905 100644
--- a/gdbsupport/span.h
+++ b/gdbsupport/span.h
@@ -69,20 +69,6 @@ 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 */
@@ -212,32 +198,6 @@ class span
size_type m_size;
};
-namespace ranges
-{
-
-namespace ranges
-{
-
-/* 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. */
-
-template <typename T>
-bool
-equal (const gdb::span<T> &lhs, const gdb::span<T> &rhs)
-{
- if (lhs.size () != rhs.size ())
- return false;
-
- for (size_t i = 0; i < lhs.size (); i++)
- if (!(lhs[i] == rhs[i]))
- return false;
-
- return true;
-}
-
-} /* namespace ranges */
-
} /* namespace gdb */
#endif /* __cplusplus < 202002L */
--
2.56.0
next prev parent reply other threads:[~2026-11-17 22:11 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 22:09 [PATCH v3 00/17] Rename gdb::array_view to gdb::span Tom Tromey
2026-11-17 22:09 ` [PATCH v3 01/17] Rename array_view files Tom Tromey
2026-11-17 22:09 ` [PATCH v3 02/17] Rename gdb::array_view to gdb::span Tom Tromey
2026-11-17 22:09 ` [PATCH v3 03/17] Rename gdb::make_array_view to gdb::make_span Tom Tromey
2026-11-17 22:10 ` [PATCH v3 04/17] Rename gdb_argv::as_array_view Tom Tromey
2026-11-17 22:10 ` [PATCH v3 05/17] Remove operator== and operator!= from gdb::span Tom Tromey
2026-11-17 22:10 ` [PATCH v3 06/17] Rename span::slice to span::subspan Tom Tromey
2026-11-17 22:10 ` [PATCH v3 07/17] Qualify calls to gdb::copy Tom Tromey
2026-11-17 22:10 ` [PATCH v3 08/17] Add single-argument overloads of process_options et al Tom Tromey
2026-11-17 22:10 ` [PATCH v3 09/17] Remove span from cli-option.c:build_help_option Tom Tromey
2026-11-17 22:10 ` [PATCH v3 10/17] Don't use the single-argument gdb::span constructor Tom Tromey
2026-11-17 22:10 ` [PATCH v3 11/17] Don't turn rvalue reference into a span Tom Tromey
2026-11-17 22:10 ` [PATCH v3 12/17] gdb/unittests: use one static_assert per check in span-selftests.c Tom Tromey
2026-11-17 22:10 ` [PATCH v3 13/17] Change span-selftests.c for C++20 Tom Tromey
2026-11-17 22:10 ` [PATCH v3 14/17] Make gdb::span conform more closely to C++20 Tom Tromey
2026-11-17 22:10 ` [PATCH v3 15/17] Allow the use of C++20 std::ranges in gdbsupport/ranges.h Tom Tromey
2026-11-17 22:10 ` [PATCH v3 16/17] Allow the use of C++20 std::span in gdbsupport/span.h Tom Tromey
2026-11-17 22:10 ` Tom Tromey [this message]
2026-11-18 15:04 ` [PATCH v3 00/17] Rename gdb::array_view to gdb::span Tom Tromey
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=20261117-span-part-1-v3-17-40b8b11d2d8c@adacore.com \
--to=tromey@adacore.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@efficios.com \
/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