6#include <initializer_list>
28 template <
typename,
typename =
void>
29 struct HasSize : std::false_type {};
32 struct HasSize<C, std::void_t<decltype(std::size(std::declval<C>()))>> : std::true_type {};
34 template <
typename,
typename =
void>
35 struct HasData : std::false_type {};
38 struct HasData<C, std::void_t<decltype(std::data(std::declval<C>()))>> : std::true_type {};
41 using EnableIfHasSizeAndData =
42 typename std::enable_if_t<HasSize<C>::value && HasData<C>::value>;
60 constexpr Span() noexcept = default;
69 template <
typename Container,
typename = EnableIfHasSizeAndData<Container>>
70 constexpr Span(Container& container)
noexcept
71 :
Span(std::data(container), std::size(container)) {}
76 template <
typename Container,
typename = EnableIfHasSizeAndData<Container>>
77 constexpr Span(
const Container& container)
noexcept
78 :
Span(std::data(container), std::size(container)) {}
93 constexpr Span(std::initializer_list<value_type> values) noexcept
94 :
Span(values.begin(), values.size()) {}
97 std::swap(data_, other.data_);
98 std::swap(size_, other.size_);
101 [[nodiscard]]
constexpr size_t size() const noexcept {
105 [[nodiscard]]
constexpr bool empty() const noexcept {
114 assert(index <
size());
115 return data()[index];
162 size_t offset,
size_t count = (std::numeric_limits<std::size_t>::max)()
164 if (offset >=
size()) {
167 if (count >
size() - offset) {
168 count =
size() - offset;
170 return {
data() + offset, count};
174 [[nodiscard]]
constexpr Span first(
size_t count)
const noexcept {
175 if (count >=
size()) {
178 return {
data(), count};
182 [[nodiscard]]
constexpr Span last(
size_t count)
const noexcept {
183 if (count >=
size()) {
186 return {
data() + (
size() - count), count};
196template <
typename Container>
199template <
typename Container>
218template <
typename T,
typename U>
220 std::is_invocable_v<std::equal_to<>,
const T&,
const U&> &&
221 std::is_invocable_v<std::not_equal_to<>,
const T&,
const U&>>;
225template <
typename T,
typename U,
typename = detail::EnableIfEqualityComparable<T, U>>
230template <
typename T,
typename U,
typename = detail::EnableIfEqualityComparable<T, U>>
232 return !(lhs == rhs);
View to a contiguous sequence of objects, similar to std::span in C++20.
constexpr const_reverse_iterator crend() const noexcept
std::remove_cv_t< T > value_type
const T & const_reference
constexpr Span last(size_t count) const noexcept
Obtain a view over the last count elements of this Span.
constexpr reverse_iterator rend() const noexcept
constexpr reference operator[](size_t index) const noexcept
constexpr const_iterator cbegin() const noexcept
constexpr iterator begin() const noexcept
constexpr Span() noexcept=default
constexpr Span(std::initializer_list< value_type > values) noexcept
Implicit constructor from an initializer list.
constexpr bool empty() const noexcept
constexpr void swap(Span &other) noexcept
constexpr Span subview(size_t offset, size_t count=(std::numeric_limits< std::size_t >::max)()) const noexcept
Obtain a view over count elements of this Span starting at offset offset.
std::reverse_iterator< const_iterator > const_reverse_iterator
constexpr const_reverse_iterator crbegin() const noexcept
constexpr size_t size() const noexcept
constexpr reference front() const noexcept
constexpr Span(Container &container) noexcept
Implicit constructor from a container like std::array or std::vector.
std::reverse_iterator< iterator > reverse_iterator
constexpr reverse_iterator rbegin() const noexcept
constexpr reference back() const noexcept
const_pointer const_iterator
std::ptrdiff_t difference_type
constexpr iterator end() const noexcept
constexpr const_iterator cend() const noexcept
constexpr pointer data() const noexcept
constexpr Span(const Container &container) noexcept
Implicit constructor from a container like std::array or std::vector (const).
constexpr Span first(size_t count) const noexcept
Obtain a view over the first count elements of this Span.
typename std::enable_if_t< std::is_invocable_v< std::equal_to<>, const T &, const U & > && std::is_invocable_v< std::not_equal_to<>, const T &, const U & > > EnableIfEqualityComparable
Span(Container &) -> Span< typename Container::value_type >
bool operator!=(const Client &lhs, const Client &rhs) noexcept
bool operator==(const Client &lhs, const Client &rhs) noexcept