MCPcopy Create free account
hub / github.com/ashvardanian/StringZilla / span

Class span

include/stringzilla/types.hpp:174–219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

172
173template <typename value_type_, sz_size_t extent_ = SZ_SIZE_MAX>
174struct span {
175
176 using value_type = value_type_; // ? For STL compatibility
177 using size_type = sz_size_t; // ? For STL compatibility
178 using difference_type = sz_ssize_t; // ? For STL compatibility
179 static constexpr sz_size_t extent = extent_; // ? For STL compatibility
180
181 value_type *data_ {};
182
183 constexpr span() noexcept = default;
184 constexpr span(value_type *data) noexcept : data_(data) {}
185 sz_constexpr_if_cpp14 span(value_type *data, size_type size) noexcept : data_(data) {
186 sz_assert_(extent == size && "The second argument is only intended for compatibility");
187 sz_unused_(size);
188 }
189
190 sz_constexpr_if_cpp14 explicit operator bool() const noexcept { return data_ != nullptr; }
191
192 constexpr value_type *begin() const noexcept { return data_; }
193 constexpr value_type *end() const noexcept { return data_ + extent; }
194 constexpr value_type *data() const noexcept { return data_; }
195 constexpr size_type size() const noexcept { return extent; }
196 constexpr size_type length() const noexcept { return extent; }
197 constexpr size_type size_bytes() const noexcept { return extent * sizeof(value_type); }
198 constexpr value_type &operator[](size_type i) const noexcept { return data_[i]; }
199 constexpr value_type &front() const noexcept { return data_[0]; }
200 constexpr value_type &back() const noexcept { return data_[extent - 1]; }
201 constexpr bool empty() const noexcept { return extent == 0; }
202
203 template <typename same_value_type_ = value_type,
204 typename = typename std::enable_if<!std::is_const<same_value_type_>::value>::type>
205 constexpr operator span<typename std::add_const<same_value_type_>::type>() const noexcept {
206 return {data_};
207 }
208
209 template <typename other_value_type_>
210 constexpr span<other_value_type_, extent * sizeof(value_type) / sizeof(other_value_type_)> cast() const noexcept {
211 return span<other_value_type_, extent * sizeof(value_type) / sizeof(other_value_type_)>(
212 reinterpret_cast<other_value_type_ *>(data_));
213 }
214
215 sz_constexpr_if_cpp14 span<value_type, SZ_SIZE_MAX> subspan(size_type offset, size_type count) const noexcept {
216 sz_assert_(offset + count <= extent && "Subspan out of bounds");
217 return span<value_type, SZ_SIZE_MAX>(data_ + offset, count);
218 }
219};
220
221template <typename value_type_>
222struct span<value_type_, SZ_SIZE_MAX> {

Callers 8

subspanMethod · 0.85
basic_stringClass · 0.85
operator[]Method · 0.85
satMethod · 0.85
frontMethod · 0.85
backMethod · 0.85
subMethod · 0.85
try_appendMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…