9#ifndef HEADER_SQLITEPP_SPAN_INCLUDED
10#define HEADER_SQLITEPP_SPAN_INCLUDED
17#if __cplusplus > 201703L
48 template <
class T>
class span;
50 namespace span_internal
59 using is_span = is_span_impl<std::decay_t<T>>;
64 template <
class T,
size_t N>
68 using is_std_array = is_std_array_impl<std::decay_t<T>>;
73 template <
class From,
class To>
76 template <
class Container,
class T>
77 using container_has_convertible_data = is_legal_data_conversion<
81 template <
class Container>
82 using container_has_integral_size =
86 template <
class Container,
class T>
87 using is_span_compatible_container =
89 !is_std_array<Container>::value &&
90 !is_c_array<Container>::value &&
91 container_has_convertible_data<Container, T>::value &&
92 container_has_integral_size<Container>::value,
103 using element_type = T;
105 using index_type = size_t;
106 using difference_type = ptrdiff_t;
108 using const_pointer =
const T *;
109 using reference = T &;
110 using const_reference =
const T &;
111 using iterator = pointer;
112 using const_iterator = const_pointer;
117 constexpr span() noexcept : _data{
nullptr}, _size{0} {}
119 constexpr span (
const span&)
noexcept =
default;
120 constexpr span& operator=(
const span&)
noexcept =
default;
122 constexpr span(pointer ptr, index_type count) noexcept : _data{ptr}, _size{
count} {}
123 constexpr span(pointer first, pointer last) noexcept : _data{first}, _size{
static_cast<size_t>(
std::distance(first, last))} {}
126 constexpr span(element_type (&arr)[N]) noexcept : _data{arr}, _size{N} {}
134 template <
class Container>
135 constexpr span(Container& cont,
139 template <
class Container>
140 constexpr span(
const Container& cont,
145 template <
class OtherElementType>
150 : _data{other.data()}, _size{other.size()} {}
155 assert(count <=
size());
161 assert(count <=
size());
166 subspan(index_type offset, index_type count =
size_t(-1)) const noexcept
168 assert(offset <=
size());
169 assert(count <=
size() || count ==
size_t(-1));
170 if (count ==
size_t(-1))
171 return {
data() + offset,
size() - offset};
172 assert(offset <=
size() - count);
176 constexpr index_type
size() const noexcept {
return _size; }
177 constexpr index_type size_bytes() const noexcept {
return _size *
sizeof(element_type); }
178 constexpr bool empty() const noexcept {
return _size == 0; }
180 constexpr reference operator[](index_type idx)
const noexcept
182 assert(idx <
size());
186 constexpr reference front() const noexcept
192 constexpr reference back() const noexcept
195 return _data[
size()-1];
199 constexpr pointer
data() const noexcept {
return _data; }
201 constexpr iterator
begin() const noexcept {
return iterator(
data()); }
202 constexpr iterator
end() const noexcept {
return iterator(
data() +
size()); }
203 constexpr const_iterator
cbegin() const noexcept {
return const_iterator(
data()); }
204 constexpr const_iterator
cend() const noexcept {
return const_iterator(
data() +
size()); }
205 constexpr reverse_iterator
rbegin() const noexcept {
return reverse_iterator(
end()); }
206 constexpr reverse_iterator
rend() const noexcept {
return reverse_iterator(
begin()); }
207 constexpr const_reverse_iterator
crbegin() const noexcept {
return const_reverse_iterator(
cend()); }
208 constexpr const_reverse_iterator
crend() const noexcept {
return const_reverse_iterator(
cbegin()); }
210 constexpr void swap(
span &other)
noexcept
216 index_type s = _size;
260 using index_type = size_t;
261 using difference_type = ptrdiff_t;
273 using difference_type = zero_blob::difference_type;
277 constexpr const_iterator()
noexcept =
default;
279 constexpr const_reference operator*()
const noexcept {
return s_value; }
281 constexpr const_iterator & operator++()
noexcept { ++_idx;
return *
this; }
282 constexpr const_iterator operator++(
int)
noexcept {
return _idx++; }
283 constexpr const_iterator & operator+=(difference_type diff)
noexcept { _idx += diff;
return *
this; }
285 constexpr const_iterator & operator--()
noexcept { --_idx;
return *
this; }
286 constexpr const_iterator operator--(
int)
noexcept {
return _idx--; }
287 constexpr const_iterator & operator-=(difference_type diff)
noexcept { _idx -= diff;
return *
this; }
289 friend constexpr difference_type operator-(const_iterator lhs, const_iterator rhs)
noexcept {
return lhs._idx - rhs._idx; }
291 friend constexpr bool operator==(const_iterator lhs, const_iterator rhs)
noexcept {
return lhs._idx == rhs._idx; };
292 friend constexpr bool operator!=(const_iterator lhs, const_iterator rhs)
noexcept {
return lhs._idx != rhs._idx; };
293 friend constexpr bool operator<(const_iterator lhs, const_iterator rhs)
noexcept {
return lhs._idx < rhs._idx; };
294 friend constexpr bool operator<=(const_iterator lhs, const_iterator rhs)
noexcept {
return lhs._idx <= rhs._idx; };
295 friend constexpr bool operator>(const_iterator lhs, const_iterator rhs)
noexcept {
return lhs._idx > rhs._idx; };
296 friend constexpr bool operator>=(const_iterator lhs, const_iterator rhs)
noexcept {
return lhs._idx >= rhs._idx; };
298 constexpr const_iterator(
size_t idx) noexcept : _idx(idx) {};
300 size_t _idx = size_t(-1);
303 using iterator = const_iterator;
308 constexpr zero_blob(
size_t size = 0) noexcept : _size{size} {}
313 constexpr zero_blob first(index_type count)
const noexcept
315 assert(count <= size());
319 constexpr zero_blob last (index_type count)
const noexcept
321 assert(count <= size());
326 subspan(index_type offset, index_type count =
size_t(-1))
const noexcept
328 assert(offset <= size());
329 assert(count <= size() || count ==
size_t(-1));
330 if (count ==
size_t(-1))
331 return {size() - offset};
332 assert(offset <= size() - count);
336 constexpr index_type size()
const noexcept {
return _size; }
337 constexpr index_type size_bytes()
const noexcept {
return _size *
sizeof(
element_type); }
338 constexpr bool empty()
const noexcept {
return _size == 0; }
340 constexpr reference operator[](index_type idx)
const noexcept
342 assert(idx < size());
347 constexpr reference front()
const noexcept
353 constexpr reference back()
const noexcept
359 constexpr iterator begin()
const noexcept {
return iterator(0); }
360 constexpr iterator end()
const noexcept {
return iterator(size()); }
361 constexpr const_iterator cbegin()
const noexcept {
return const_iterator(0); }
362 constexpr const_iterator cend()
const noexcept {
return const_iterator(size()); }
370 static inline const std::byte s_value{0};
An efficient blob of zeroes of a given size.
Definition span.hpp:256
std::span< T > span
Alias or reimplementation of std::span.
Definition span.hpp:35
ThinSQLite++ namespace.
Definition backup_iface.hpp:17