3#include <sysio/vm/exceptions.hpp>
10namespace sysio {
namespace vm {
11 inline static constexpr std::size_t dynamic_extent = std::numeric_limits<std::size_t>::max();
13 template <
typename T, std::
size_t Extent = dynamic_extent>
15 static_assert( Extent == 1 || Extent == dynamic_extent,
16 "only a static extent of 1 is currently available" );
28 static constexpr std::size_t
extent = Extent;
30 template<std::
size_t E = Extent,
typename Enable = std::enable_if_t<E == dynamic_extent || E == 0>>
31 constexpr span() noexcept : first_elem(
nullptr), last_elem(
nullptr) {}
36 SYS_VM_ASSERT(Extent == dynamic_extent || Extent ==
size(), span_exception,
"Wrong size for span with static extent");
40 SYS_VM_ASSERT(Extent == dynamic_extent || Extent ==
size(), span_exception,
"Wrong size for span with static extent");
43 template <std::
size_t N,
typename Enable = std::enable_if_t<(Extent == dynamic_extent || N == Extent)>>
44 inline constexpr span(
T (&arr)[
N]) noexcept : first_elem(&arr[0]), last_elem(&arr[0] +
N) {}
46 template <
typename U, std::size_t
N,
47 typename Enable = std::enable_if_t<(Extent == dynamic_extent ||
N == Extent) && std::is_convertible_v<
U(*)[],
T(*)[]>>>
48 inline constexpr span(std::array<U, N>& arr) noexcept : first_elem(arr.data()), last_elem(arr.data() +
N) {}
50 template <
typename U, std::size_t
N,
51 typename Enable = std::enable_if_t<(Extent == dynamic_extent ||
N == Extent) && std::is_convertible_v<
const U(*)[],
T(*)[]>>>
52 inline constexpr span(
const std::array<U, N>& arr) noexcept : first_elem(arr.data()), last_elem(arr.data() +
N) {}
64 inline constexpr iterator end() const noexcept {
return last_elem; }
68 inline constexpr T&
front()
const {
return *first_elem; }
69 inline constexpr T&
back()
const {
return *(last_elem - 1); }
70 inline constexpr T&
operator[](std::size_t n)
const {
return first_elem[n]; }
72 inline constexpr T*
data() const noexcept {
return first_elem; }
73 inline constexpr std::size_t
size() const noexcept {
return last_elem - first_elem; }
74 inline constexpr std::size_t
size_bytes() const noexcept {
return size() *
sizeof(
T); }
75 inline constexpr bool empty() const noexcept {
return size() == 0; }
79 return {first_elem, first_elem +
len};
84 return {last_elem -
len, last_elem};
88 if(
len == dynamic_extent)
len =
size() - offset;
89 SYS_VM_ASSERT(first_elem + offset +
len <= last_elem, span_exception,
"length overflows span");
90 return {first_elem + offset,
len};
101 template <
typename T>
103 template <
typename T>
107 template <
typename T>
108 constexpr inline static bool is_span_type_v = std::is_same_v<decltype(detail::is_span_type(std::declval<T>())), std::true_type>;
constexpr std::size_t size_bytes() const noexcept
constexpr span(const span &)=default
static constexpr std::size_t extent
constexpr iterator begin() const noexcept
constexpr span< T, dynamic_extent > last(std::size_t len) const
constexpr span(span &&)=default
constexpr T & front() const
constexpr std::size_t size() const noexcept
constexpr span< T, dynamic_extent > subspan(std::size_t offset, std::size_t len=dynamic_extent) const
constexpr T * data() const noexcept
constexpr reverse_iterator rend() const noexcept
constexpr T & operator[](std::size_t n) const
constexpr span(const std::array< U, N > &arr) noexcept
constexpr span(std::array< U, N > &arr) noexcept
constexpr T & back() const
constexpr reverse_iterator rbegin() const noexcept
constexpr span< T, dynamic_extent > first(std::size_t len) const
constexpr iterator end() const noexcept
constexpr span(pointer first, std::size_t len)
constexpr span(pointer first, pointer last)
constexpr span & operator=(const span &)=default
constexpr span & operator=(span &&)=default
constexpr span() noexcept
constexpr bool empty() const noexcept
std::remove_cv_t< T > value_type
constexpr span(T(&arr)[N]) noexcept
std::ptrdiff_t difference_type
std::reverse_iterator< iterator > reverse_iterator
const T & const_reference
constexpr std::true_type is_span_type(span< T >)
#define T(meth, val, expected)
#define SYS_VM_ASSERT(expr, exc_type, msg)