Skip to content

Commit 0ab81ca

Browse files
committed
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-source-id: 290994798 Pull Request resolved: #11757
1 parent f2078a2 commit 0ab81ca

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

runtime/core/span.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class Span final {
5555
template <size_t N>
5656
/* implicit */ constexpr Span(T (&Arr)[N]) : data_(Arr), length_(N) {}
5757

58+
/// Construct a Span from a single element reference.
59+
/* implicit */ constexpr Span(T& single_element) : data_(&single_element), length_(1) {}
60+
5861
/// @returns a pointer to the start of the underlying element buffer.
5962
iterator begin() const noexcept {
6063
return data_;

0 commit comments

Comments
 (0)