5#ifndef INCLUDE_V8_MEMORY_SPAN_H_
6#define INCLUDE_V8_MEMORY_SPAN_H_
32 template <
typename From,
typename To>
33 using is_array_convertible = std::is_convertible<From (*)[], To (*)[]>;
34 template <
typename From,
typename To>
35 static constexpr bool is_array_convertible_v =
36 is_array_convertible<From, To>::value;
38 template <
typename It>
39 using iter_reference_t =
decltype(*std::declval<It&>());
41 template <
typename It,
typename =
void>
42 struct is_compatible_iterator : std::false_type {};
43 template <
typename It>
44 struct is_compatible_iterator<
47 std::is_base_of<std::random_access_iterator_tag,
48 typename std::iterator_traits<It>::iterator_category>,
49 is_array_convertible<std::remove_reference_t<iter_reference_t<It>>,
50 T>>> : std::true_type {};
51 template <
typename It>
52 static constexpr bool is_compatible_iterator_v =
53 is_compatible_iterator<It>::value;
56 static constexpr U* to_address(U* p)
noexcept {
60 template <
typename It,
61 typename = std::void_t<decltype(std::declval<It&>().operator->())>>
62 static constexpr auto to_address(It it)
noexcept {
63 return it.operator->();
76 template <
typename Iterator,
77 std::enable_if_t<is_compatible_iterator_v<Iterator>,
bool> =
true>
80 : data_(to_address(first)), size_(count) {}
83 template <
typename Iterator,
84 std::enable_if_t<is_compatible_iterator_v<Iterator> &&
85 !std::is_convertible_v<Iterator, size_t>,
89 : data_(to_address(first)), size_(last - first) {}
94 : data_(a), size_(N) {}
97 template <
typename U,
size_t N,
98 std::enable_if_t<is_array_convertible_v<U, T>,
bool> =
true>
100 std::array<U, N>& a)
noexcept
101 : data_(a.data()), size_{N} {}
104 template <
typename U,
size_t N,
105 std::enable_if_t<is_array_convertible_v<const U, T>,
bool> =
true>
107 const std::array<U, N>& a)
noexcept
108 : data_(a.data()), size_{N} {}
111 constexpr T*
data()
const {
return data_; }
113 constexpr size_t size()
const {
return size_; }
118 constexpr bool empty()
const {
return size() == 0; }
148 explicit Iterator(T* ptr) : ptr_(ptr) {}
173template <
class T, std::size_t N, std::size_t... I>
175 T (&a)[N], std::index_sequence<I...>) {
179template <
class T, std::size_t N, std::size_t... I>
181 T (&&a)[N], std::index_sequence<I...>) {
182 return {{std::move(a[I])...}};
186template <
class T, std::
size_t N>
187constexpr std::array<std::remove_cv_t<T>, N>
to_array(T (&a)[N]) {
191template <
class T, std::
size_t N>
192constexpr std::array<std::remove_cv_t<T>, N>
to_array(T (&&a)[N]) {
194 std::make_index_sequence<N>{});
std::forward_iterator_tag iterator_category
bool operator==(Iterator other) const
bool operator!=(Iterator other) const
std::ptrdiff_t difference_type
constexpr T * data() const
constexpr T & operator[](size_t i) const
constexpr MemorySpan(std::array< U, N > &a) noexcept
constexpr MemorySpan(std::nullptr_t, size_t)
constexpr MemorySpan(const std::array< U, N > &a) noexcept
constexpr MemorySpan()=default
constexpr MemorySpan(T(&a)[N]) noexcept
constexpr size_t size() const
constexpr MemorySpan(Iterator first, size_t count)
constexpr MemorySpan(Iterator first, Iterator last)
constexpr bool empty() const
constexpr std::array< std::remove_cv_t< T >, N > to_array_rvalue_impl(T(&&a)[N], std::index_sequence< I... >)
constexpr std::array< std::remove_cv_t< T >, N > to_array_lvalue_impl(T(&a)[N], std::index_sequence< I... >)
constexpr std::array< std::remove_cv_t< T >, N > to_array(T(&a)[N])