CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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:
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 edm
36 
37 #endif
T begin() const
Definition: Span.h:20
const T end_
Definition: Span.h:33
T end() const
Definition: Span.h:21
const T begin_
Definition: Span.h:32
auto const & operator[](std::size_t idx) const
Definition: Span.h:26
auto const & front() const
Definition: Span.h:28
Span(T begin, T end)
Definition: Span.h:18
auto const & back() const
Definition: Span.h:29
Definition: Span.h:16
bool empty() const
Definition: Span.h:23
auto size() const
Definition: Span.h:24
long double T