Subversion Repositories Games.Descent

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>.
  3.  * It is copyright by its individual contributors, as recorded in the
  4.  * project's Git history.  See COPYING.txt at the top level for license
  5.  * terms and a link to the Git history.
  6.  */
  7. #pragma once
  8.  
  9. #include <cstddef>
  10.  
  11. /* Partial implementation of std::span (C++20) for pre-C++20 compilers.
  12.  * As of this writing, there are no released compilers with C++20
  13.  * support, so this implementation is always used.
  14.  *
  15.  * This implementation covers only the minimal functionality used by
  16.  * Rebirth.  It is not intended as a drop-in replacement for arbitrary
  17.  * use of std::span.
  18.  */
  19.  
  20. template <typename T>
  21. class span
  22. {
  23.         std::size_t extent;
  24.         T *ptr;
  25. public:
  26.         span(T *p, std::size_t l) :
  27.                 extent(l), ptr(p)
  28.         {
  29.         }
  30.         T *begin() const
  31.         {
  32.                 return ptr;
  33.         }
  34.         T *end() const
  35.         {
  36.                 return ptr + extent;
  37.         }
  38.         std::size_t size() const
  39.         {
  40.                 return extent;
  41.         }
  42.         T &operator[](std::size_t i) const
  43.         {
  44.                 return *(ptr + i);
  45.         }
  46. };
  47.