From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH v2 12/15] Make gdb::span conform more closely to C++20
Date: Wed, 11 Nov 2026 08:59:00 -0700 [thread overview]
Message-ID: <20261111-span-part-1-v2-12-cd4e33a8a723@adacore.com> (raw)
In-Reply-To: <20261111-span-part-1-v2-0-cd4e33a8a723@adacore.com>
This removes the single-object constructors from gdb::span, making it
conform more closely to C++20. Also, the cbegin and cend methods are
removed. These do not appear until C++23.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31422
---
gdbsupport/span.h | 28 +---------------------------
1 file changed, 1 insertion(+), 27 deletions(-)
diff --git a/gdbsupport/span.h b/gdbsupport/span.h
index 27791394d3d..e3e3ddcbbd7 100644
--- a/gdbsupport/span.h
+++ b/gdbsupport/span.h
@@ -33,10 +33,7 @@
The main intent of span is to use it as function input
parameter type, making it possible to pass in any sequence of
contiguous objects, irrespective of whether the objects live on the
- stack or heap and what actual container owns them. Implicit
- construction from the element type is supported too, making it easy
- to call functions that expect an array of elements when you only
- have one element (usually on the stack). For example:
+ stack or heap and what actual container owns them. For example:
struct A { .... };
void function (gdb::span<A> as);
@@ -44,12 +41,10 @@
std::vector<A> std_vec = ...;
std::array<A, N> std_array = ...;
A array[] = {...};
- A elem;
function (std_vec);
function (std_array);
function (array);
- function (elem);
Views can be either mutable or const. A const view is simply
created by specifying a const T as span template parameter,
@@ -88,7 +83,6 @@ class span
using reference = T &;
using const_reference = const T &;
using size_type = size_t;
- using const_iterator = const T *;
using iterator = T *;
/* Default construction creates an empty view. */
@@ -96,24 +90,6 @@ class span
: m_array (nullptr), m_size (0)
{}
- /* Create a span over a single object of the type of an
- span element. The created view as size==1. This is
- templated on U to allow constructing a span<const T> over a
- (non-const) T. The "convertible" requirement makes sure that you
- can't create an span<T> over a const T. */
- template<typename U,
- typename = Requires<DecayedConvertible<U>>>
- constexpr span (U &elem) noexcept
- : m_array (&elem), m_size (1)
- {}
-
- /* Same as above, for rvalue references. */
- template<typename U,
- typename = Requires<DecayedConvertible<U>>>
- constexpr span (U &&elem) noexcept
- : m_array (&elem), m_size (1)
- {}
-
/* Create a span from a pointer to an array and an element
count. */
template<typename U,
@@ -160,10 +136,8 @@ class span
constexpr const T *data () const noexcept { return m_array; }
constexpr iterator begin () const noexcept { return m_array; }
- constexpr const_iterator cbegin () const noexcept { return m_array; }
constexpr iterator end () const noexcept { return m_array + m_size; }
- constexpr const_iterator cend () const noexcept { return m_array + m_size; }
constexpr reference operator[] (size_t index) noexcept
{
--
2.56.0
next prev parent reply other threads:[~2026-11-11 16:03 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 15:58 [PATCH v2 00/15] Rename gdb::array_view to gdb::span Tom Tromey
2026-11-11 15:58 ` [PATCH v2 01/15] Rename array_view files Tom Tromey
2026-11-15 4:09 ` Simon Marchi
2026-11-16 15:55 ` Tom Tromey
2026-11-11 15:58 ` [PATCH v2 02/15] Rename gdb::array_view to gdb::span Tom Tromey
2026-11-15 4:18 ` Simon Marchi
2026-11-11 15:58 ` [PATCH v2 03/15] Rename gdb::make_array_view to gdb::make_span Tom Tromey
2026-11-11 15:58 ` [PATCH v2 04/15] Remove operator== and operator!= from gdb::span Tom Tromey
2026-11-11 15:58 ` [PATCH v2 05/15] Rename span::slice to span::subspan Tom Tromey
2026-11-11 15:58 ` [PATCH v2 06/15] Qualify calls to gdb::copy Tom Tromey
2026-11-11 15:58 ` [PATCH v2 07/15] Add single-argument overloads of process_options et al Tom Tromey
2026-11-11 15:58 ` [PATCH v2 08/15] Remove span from cli-option.c:build_help_option Tom Tromey
2026-11-15 3:40 ` Simon Marchi
2026-11-11 15:58 ` [PATCH v2 09/15] Add gdb::make_span overload and add necessary calls Tom Tromey
2026-11-15 3:53 ` Simon Marchi
2026-11-15 4:35 ` Simon Marchi
2026-11-16 16:55 ` Tom Tromey
2026-11-11 15:58 ` [PATCH v2 10/15] Don't turn rvalue reference into a span Tom Tromey
2026-11-11 15:58 ` [PATCH v2 11/15] Change span-selftests.c for C++20 Tom Tromey
2026-11-15 4:01 ` Simon Marchi
2026-11-15 5:15 ` Simon Marchi
2026-11-11 15:59 ` Tom Tromey [this message]
2026-11-11 15:59 ` [PATCH v2 13/15] Allow the use of C++20 std::ranges in gdbsupport/ranges.h Tom Tromey
2026-11-15 5:18 ` Simon Marchi
2026-11-11 15:59 ` [PATCH v2 14/15] Allow the use of C++20 std::span in gdbsupport/span.h Tom Tromey
2026-11-15 4:05 ` Simon Marchi
2026-11-11 15:59 ` [PATCH v2 15/15] Move gdb::ranges::equal to gdbsupport/ranges.h Tom Tromey
2026-11-15 5:21 ` [PATCH v2 00/15] Rename gdb::array_view to gdb::span Simon Marchi
2026-11-17 21:42 ` 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=20261111-span-part-1-v2-12-cd4e33a8a723@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