Fixed StrideSpan::size() for default-constructed spans and added empty check + operatators.

This commit is contained in:
Patrick 2023-11-24 13:08:39 +01:00
parent ce7a7b15c7
commit 4f7e8ae39f

View File

@ -117,10 +117,14 @@ public:
StrideSpan& operator=(const StrideSpan&) = default;
auto operator<=>(const StrideSpan&) const noexcept = default;
constexpr operator bool() const noexcept { return !empty(); }
constexpr bool operator!() const noexcept { return empty(); }
reference operator[](size_type index);
const_reference operator[](size_type index) const;
[[nodiscard]] constexpr size_type size() const noexcept { return bytediff(begin_, end_) / strideBytes_; }
[[nodiscard]] constexpr size_type size() const noexcept { return strideBytes_ == 0 ? 0 : bytediff(begin_, end_) / strideBytes_; }
[[nodiscard]] constexpr bool empty() const noexcept { return begin_ == end_; }
[[nodiscard]] iterator begin() { return StrideSpanIterator<T>(begin_, strideBytes_, begin_, end_); }
[[nodiscard]] const_iterator begin() const { return StrideSpanIterator<const T>(begin_, strideBytes_, begin_, end_); }