Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update span.h to fix breaks #86

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#ifndef USE_CXX17
#include <span>
#else
#include <vector>
namespace std {

template <typename T>
Expand All @@ -12,6 +13,8 @@ struct span {

span(const span<std::remove_const_t<T> >& s) : p_{const_cast<T*>(s.data())}, length_{s.size()} {}
span(std::vector<std::remove_const_t<T> >& s) : p_{const_cast<T*>(s.data())}, length_{s.size()} {}
template <auto N>
span(std::array<std::remove_const_t<T>, N> s) : p_{const_cast<T*>(s.data())}, length_{s.size()} {}

bool empty() const { return length_ == 0; }

Expand All @@ -21,16 +24,14 @@ struct span {
T* data() { return p_; }
const T* data() const { return p_; }

T& operator[](size_t index) { return p_[index]; }
T& operator[](size_t index) const { return p_[index]; }

T& back() { return p_[length_ - 1]; }
T back() const { return p_[length_ - 1]; }
T& back() const { return p_[length_ - 1]; }

T* begin() { return p_; }
T* end() { return p_ + length_; }
T* begin() const { return p_; }
T* end() const { return p_ + length_; }

span subspan(size_t index, size_t length) { return span(p_ + index, length); }
span<const T> subspan(size_t index, size_t length) const { return span(p_ + index, length); }
span subspan(size_t index, size_t length) const { return span(p_ + index, length); }

private:
T* p_{};
Expand Down
Loading