ulfben

span

Feb 12th, 2020
272
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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×