From 739a353ff6044fa7d66b597df1174c3e4760f9a4 Mon Sep 17 00:00:00 2001 From: Chen Lai Date: Tue, 17 Jun 2025 09:12:39 -0700 Subject: [PATCH] Support Span to construct from a single element similar to ArrayRef Copy the constructor from ArrayRef here https://github.com/pytorch/executorch/blob/5365c5559accc7a0d522eacdfb7385ce8914ef53/runtime/core/array_ref.h#L78-L81 so it's easier to use Differential Revision: [D76825662](https://our.internmc.facebook.com/intern/diff/D76825662/) [ghstack-poisoned] --- runtime/core/span.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/runtime/core/span.h b/runtime/core/span.h index 1bcde396ccd..57da63f01e6 100644 --- a/runtime/core/span.h +++ b/runtime/core/span.h @@ -55,6 +55,9 @@ class Span final { template /* implicit */ constexpr Span(T (&Arr)[N]) : data_(Arr), length_(N) {} + /// Construct a Span from a single element reference. + /* implicit */ constexpr Span(T& single_element) : data_(&single_element), length_(1) {} + /// @returns a pointer to the start of the underlying element buffer. iterator begin() const noexcept { return data_;