Skip to content

Commit

Permalink
Add span::empty() and fix const-correctness bug in as_writable_bytes()
Browse files Browse the repository at this point in the history
  • Loading branch information
Lewis Baker authored and lewissbaker committed Jan 14, 2021
1 parent 2f460de commit 95f5e4b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion include/unifex/span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ struct span {
return Extent;
}

constexpr bool empty() const noexcept {
return Extent == 0;
}

T* begin() const noexcept {
return data();
}
Expand Down Expand Up @@ -173,6 +177,10 @@ struct span<T, dynamic_extent> {
return data_;
}

bool empty() const noexcept {
return size_ == 0;
}

std::size_t size() const noexcept {
return size_;
}
Expand Down Expand Up @@ -294,7 +302,7 @@ span<std::byte, Extent * sizeof(T)> as_writable_bytes(
const span<T, Extent>& s) noexcept {
constexpr std::size_t maxSize = std::size_t(-1) / sizeof(T);
static_assert(Extent <= maxSize);
return span<const std::byte, Extent * sizeof(T)>{
return span<std::byte, Extent * sizeof(T)>{
reinterpret_cast<std::byte*>(s.data())};
}

Expand Down

0 comments on commit 95f5e4b

Please sign in to comment.