Span.h
Go to the documentation of this file.
1 #ifndef NuSonic_Triton_Span_h
2 #define NuSonic_Triton_Span_h
3 
4 #include <cstddef>
5 
6 namespace triton_span {
7  /*
8  *An edm::Span wraps begin() and end() iterators to a contiguous sequence
9  of objects with the first element of the sequence at position zero,
10  In other words the iterators should refer to random-access containers.
11 
12  To be replaced with std::Span in C++20.
13  */
14 
15  template <class T>
16  class Span {
17  public:
18  Span(T begin, T end) : begin_(begin), end_(end) {}
19 
20  T begin() const { return begin_; }
21  T end() const { return end_; }
22 
23  bool empty() const { return begin_ == end_; }
24  auto size() const { return end_ - begin_; }
25 
26  auto const& operator[](std::size_t idx) const { return *(begin_ + idx); }
27 
28  auto const& front() const { return *begin_; }
29  auto const& back() const { return *(end_ - 1); }
30 
31  private:
32  const T begin_;
33  const T end_;
34  };
35 } // namespace triton_span
36 
37 #endif
auto const & back() const
Definition: Span.h:29
T begin() const
Definition: Span.h:20
Span(T begin, T end)
Definition: Span.h:18
T end() const
Definition: Span.h:21
auto const & operator[](std::size_t idx) const
Definition: Span.h:26
const T end_
Definition: Span.h:33
auto size() const
Definition: Span.h:24
const T begin_
Definition: Span.h:32
bool empty() const
Definition: Span.h:23
auto const & front() const
Definition: Span.h:28