1 #ifndef ZSERIO_SPAN_H_INC
2 #define ZSERIO_SPAN_H_INC
17 constexpr std::size_t
dynamic_extent = std::numeric_limits<std::size_t>::max();
22 template <
typename T, std::
size_t Extent>
25 SpanStorage() =
default;
27 SpanStorage(T* data, std::size_t) :
32 static constexpr std::size_t m_size = Extent;
38 SpanStorage() =
default;
40 SpanStorage(T* data, std::size_t size) :
46 std::size_t m_size = 0;
57 template <
typename T, std::
size_t Extent = dynamic_extent>
79 typename std::enable_if<(ext == 0 || ext ==
dynamic_extent),
int>::type = 0>
91 m_storage(first_, count)
102 m_storage(first_, static_cast<size_t>(last_ - first_))
111 typename std::enable_if<(ext ==
dynamic_extent || ext == N),
int>::type = 0>
123 std::is_convertible<U (*)[], T (*)[]>::value,
125 constexpr
Span(std::array<U, N>& arr) noexcept :
126 m_storage(arr.data(), arr.size())
136 std::is_convertible<
const U (*)[], T (*)[]>::value,
138 constexpr
Span(
const std::array<U, N>& arr) noexcept :
139 m_storage(arr.data(), arr.size())
147 template <
typename U,
typename ALLOC,
size_type ext = Extent,
148 typename std::enable_if<(ext ==
dynamic_extent) && std::is_convertible<U (*)[], T (*)[]>::value,
150 constexpr
Span(std::vector<U, ALLOC>& vec) :
159 template <
typename U,
typename ALLOC,
size_type ext = Extent,
160 typename std::enable_if<
161 (ext ==
dynamic_extent) && std::is_convertible<
const U (*)[], T (*)[]>::value,
int>::type =
163 constexpr
Span(
const std::vector<U, ALLOC>& vec) :
173 typename std::enable_if<(Extent == N || Extent ==
dynamic_extent) &&
174 std::is_convertible<U (*)[], T (*)[]>::value,
177 m_storage(span.data(), span.size())
273 return m_storage.m_data;
283 return m_storage.m_size;
301 constexpr
bool empty() const noexcept
311 template <
size_type Count>
314 static_assert(Count <= Extent,
"Requested number of characters out of range.");
334 template <
size_type Count>
337 static_assert(Count <= Extent,
"Requested number of characters out of range.");
352 template <
size_type Offset,
size_type Count>
363 typename std::enable_if<Count == dynamic_extent, int>::type = 0>
367 "Requested number of characters out of range.");
372 typename std::enable_if<Count != dynamic_extent, int>::type = 0>
375 static_assert((Extent ==
dynamic_extent) || (Offset <= Extent && Offset + Count <= Extent),
376 "Requested number of characters out of range.");
396 detail::SpanStorage<T, Extent> m_storage;
constexpr Span(pointer first_, size_type count)
constexpr bool empty() const noexcept
Span & operator=(Span &&other) noexcept=default
constexpr reference front() const
constexpr Span() noexcept
Span(const Span &other) noexcept=default
constexpr size_type size() const noexcept
constexpr Span< element_type, dynamic_extent > last(size_type Count) const
static constexpr size_type extent
constexpr Span(const Span< U, N > &span) noexcept
constexpr Span< element_type, Count > last() const
constexpr Span(pointer first_, pointer last_)
constexpr reverse_iterator rbegin() const noexcept
std::ptrdiff_t difference_type
constexpr reverse_iterator rend() const noexcept
const_pointer const_iterator
constexpr Span< element_type, dynamic_extent > subspan(size_type Offset, size_type Count=dynamic_extent) const
typename std::remove_cv< T >::type value_type
constexpr reference back() const
constexpr Span(const std::vector< U, ALLOC > &vec)
constexpr pointer data() const noexcept
constexpr SubspanReturnType< Offset, Count > subspan() const
std::reverse_iterator< iterator > reverse_iterator
Span(Span &&other) noexcept=default
constexpr size_type size_bytes() const noexcept
constexpr Span(const std::array< U, N > &arr) noexcept
constexpr reference operator[](size_type idx) const
constexpr Span< element_type, Count > first() const
constexpr Span< element_type, dynamic_extent > first(size_type Count) const
std::reverse_iterator< const_iterator > const_reverse_iterator
constexpr Span(std::array< U, N > &arr) noexcept
Span & operator=(const Span &other) noexcept=default
constexpr Span(element_type(&arr)[N]) noexcept
constexpr Span(std::vector< U, ALLOC > &vec)
constexpr iterator end() const noexcept
constexpr iterator begin() const noexcept
constexpr std::size_t dynamic_extent