CMS 3D CMS Logo

Span.h
Go to the documentation of this file.
1 #ifndef FWCore_Utilities_Span_h
2 #define FWCore_Utilities_Span_h
3 
4 #include <cstddef>
5 
6 namespace edm {
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:
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 edm
36 
37 #endif
const T end_
Definition: Span.h:33
const T begin_
Definition: Span.h:32
Span(T begin, T end)
Definition: Span.h:18
auto size() const
Definition: Span.h:24
T begin() const
Definition: Span.h:20
bool empty() const
Definition: Span.h:23
auto const & operator[](std::size_t idx) const
Definition: Span.h:26
HLT enums.
auto const & back() const
Definition: Span.h:29
Definition: Span.h:16
auto const & front() const
Definition: Span.h:28
long double T
T end() const
Definition: Span.h:21