Skip to content

Commit 42c8baa

Browse files
committed
Restore std::array constructors for ArrayRef
Checked with suo, shouldn't be any reason to keep these gone. ghstack-source-id: 36ede97 ghstack-comment-id: 2613189181 Pull Request resolved: #7942
1 parent 7600f18 commit 42c8baa

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

runtime/core/array_ref.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
// removed some implicit const -> non-const conversions that rely on
2020
// complicated std::enable_if meta-programming
2121
// removed a bunch of slice variants for simplicity...
22-
// remove constructors for std::array
2322
// remove constructors and operators for std::vector
2423
// removed some prevention of accidental assignments from temporary that
2524
// required std::enable_if meta-programming
2625
// removed reverse iterator
2726

2827
#pragma once
2928

29+
#include <array>
3030
#include <cstdint>
3131

3232
#include <executorch/runtime/platform/assert.h>
@@ -87,6 +87,11 @@ class ArrayRef final {
8787
/// Construct a ArrayRef from a range.
8888
ArrayRef(const T* begin, const T* end) : Data(begin), Length(end - begin) {}
8989

90+
/// Construct an ArrayRef from a std::array
91+
template <size_t N>
92+
/* implicit */ constexpr ArrayRef(const std::array<T, N>& Arr)
93+
: Data(Arr.data()), Length(N) {}
94+
9095
/// Construct a ArrayRef from a C array.
9196
template <size_t N>
9297
/* implicit */ constexpr ArrayRef(const T (&Arr)[N]) : Data(Arr), Length(N) {}
@@ -202,6 +207,12 @@ ArrayRef<T> makeArrayRef(const T* begin, const T* end) {
202207
return ArrayRef<T>(begin, end);
203208
}
204209

210+
/// Construct an ArrayRef from a std::array.
211+
template <typename T, std::size_t N>
212+
ArrayRef<T> makeArrayRef(const std::array<T, N>& Arr) {
213+
return Arr;
214+
}
215+
205216
/// Construct an ArrayRef from an ArrayRef (no-op) (const)
206217
template <typename T>
207218
ArrayRef<T> makeArrayRef(const ArrayRef<T>& Vec) {

0 commit comments

Comments
 (0)