7#include <userver/utils/assert.hpp>
11namespace utils::impl {
17 using const_iterator = T*;
19 constexpr Span() : Span(
nullptr,
nullptr) {}
21 constexpr Span(T* begin, T* end)
noexcept : begin_(begin), end_(end) {
22 UASSERT((begin !=
nullptr && end !=
nullptr && begin <= end) ||
23 (begin ==
nullptr && end ==
nullptr));
28 typename = std::enable_if_t<
30 !std::is_same_v<
decltype(*std::begin(std::declval<Container&&>())),
33 !std::is_same_v<std::remove_cv_t<std::remove_reference_t<Container>>,
35 constexpr Span(Container&& cont)
noexcept
36 : Span(std::data(cont), std::data(cont) + std::size(cont)) {}
38 constexpr T* begin()
const noexcept {
return begin_; }
39 constexpr T* end()
const noexcept {
return end_; }
41 constexpr T* data()
const noexcept {
return begin_; }
42 constexpr std::size_t size()
const noexcept {
return end_ - begin_; }
44 constexpr Span<T> first(std::size_t count)
const noexcept {
46 return Span{begin_, begin_ + count};
49 constexpr Span<T> last(std::size_t count)
const noexcept {
51 return Span{end_ - count, end_};
54 constexpr Span<T> subspan(std::size_t offset, std::size_t count)
const
56 UASSERT(offset + count <= size());
57 return Span{begin_ + offset, begin_ + offset + count};
60 constexpr T& operator[](std::size_t index)
const noexcept {
70template <
typename Container>
72 -> Span<std::remove_reference_t<
decltype(*std::begin(cont))>>;