Skip to content

Commit a0fd136

Browse files
committed
Improve: Pointer-constructible spans
1 parent 0a26059 commit a0fd136

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

include/stringzilla/types.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,16 @@ struct span {
141141
value_type *data_ {};
142142
size_type size_ {};
143143

144+
constexpr span() noexcept = default;
145+
constexpr span(value_type *data, size_type size) noexcept : data_(data), size_(size) {}
146+
constexpr span(value_type *data, value_type *end) noexcept : data_(data), size_(end - data) {}
147+
144148
constexpr value_type *begin() const noexcept { return data_; }
145149
constexpr value_type *end() const noexcept { return data_ + size_; }
146150
constexpr value_type *data() const noexcept { return data_; }
147151
constexpr size_type size() const noexcept { return size_; }
148152
constexpr size_type length() const noexcept { return size_; }
153+
constexpr size_type size_bytes() const noexcept { return size_ * sizeof(value_type); }
149154
constexpr value_type &operator[](size_type i) const noexcept { return data_[i]; }
150155
};
151156

0 commit comments

Comments
 (0)