Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<class T>
- class base_span{
- public:
- constexpr base_span(std::nullptr_t):
- _begin(nullptr),
- _size(0)
- {
- }
- constexpr base_span(T* begin, T* end):
- _begin(begin),
- _size(end - begin)
- {
- }
- constexpr base_span(T* begin, uword size) :
- _begin(begin),
- _size(size) {
- }
- constexpr base_span(std::initializer_list<T> init) :
- _begin(init.begin()),
- _size(init.size()) {
- }
- template<size_t N>
- constexpr base_span(T(&static_array)[N]):
- _begin(static_array),
- _size(N)
- {
- }
- constexpr T* begin() const{
- return _begin;
- }
- constexpr T* end() const{
- return _begin + _size;
- }
- constexpr T* data() const{
- return _begin;
- }
- constexpr uword size() const{
- return _size;
- }
- constexpr T& operator[](uword index) const{
- octo_assert(index < _size);
- return _begin[index];
- }
- constexpr operator base_span<const T>() const{
- return {_begin, _size};
- }
- constexpr base_span<T> slice(uword start, uword end) const{
- return {_begin + start, _begin + start + end};
- }
- private:
- T* _begin;
- uword _size;
- };
- template<class T>
- using span = base_span<const T>;
- template<class T>
- using mut_span = base_span<T>;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement