SHARE
TWEET

span

ulfben Feb 12th, 2020 (edited) 229 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <cstdint>
  2.  
  3. template<typename T>
  4. class span {
  5.    T* ptr_;
  6.    std::size_t len_;
  7. public:
  8.    using value_type = std::remove_cv_t<T>; //primarily needed if used with templates
  9.  
  10.    span(T* ptr, std::size_t len) noexcept : ptr_{ptr}, len_{len} {}
  11.  
  12.    T& operator[](int i) noexcept { return *ptr_[i]; }
  13.    T const& operator[](int i) const noexcept { return *ptr_[i]; }
  14.  
  15.    bool empty() const noexcept { return len_ == 0; }
  16.    auto size() const noexcept { return len_; }
  17.  
  18.    auto begin() noexcept { return ptr_; }  
  19.    auto begin() const noexcept { return ptr_; }
  20.    auto end() noexcept { return ptr_ + len_; } 
  21.    auto end() const noexcept { return ptr_ + len_; }
  22. };
  23. static_assert(_MSVC_LANG <= 201703L, "Remember to switch to std::span");
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top