diff --git a/DataFormats/NanoAOD/interface/FlatTable.h b/DataFormats/NanoAOD/interface/FlatTable.h index c2be6b19264fd..e7f62817bc99d 100644 --- a/DataFormats/NanoAOD/interface/FlatTable.h +++ b/DataFormats/NanoAOD/interface/FlatTable.h @@ -3,7 +3,7 @@ #include "DataFormats/Math/interface/libminifloat.h" #include "FWCore/Utilities/interface/Exception.h" -#include "FWCore/Utilities/interface/Range.h" +#include "FWCore/Utilities/interface/Span.h" #include #include @@ -17,8 +17,8 @@ namespace nanoaod { struct MaybeMantissaReduce { MaybeMantissaReduce(int mantissaBits) {} inline T one(const T &val) const { return val; } - template - inline void bulk(Range &&data) const {} + template + inline void bulk(Span &&data) const {} }; template <> struct MaybeMantissaReduce { @@ -27,8 +27,8 @@ namespace nanoaod { inline float one(const float &val) const { return (bits_ > 0 ? MiniFloatConverter::reduceMantissaToNbitsRounding(val, bits_) : val); } - template - inline void bulk(Range &&data) const { + template + inline void bulk(Span &&data) const { if (bits_ > 0) MiniFloatConverter::reduceMantissaToNbitsRounding(bits_, data.begin(), data.end(), data.begin()); } @@ -69,14 +69,14 @@ namespace nanoaod { template auto columnData(unsigned int column) const { auto begin = beginData(column); - return edm::Range(begin, begin + size_); + return edm::Span(begin, begin + size_); } /// get a column by index (non-const) template auto columnData(unsigned int column) { auto begin = beginData(column); - return edm::Range(begin, begin + size_); + return edm::Span(begin, begin + size_); } /// get a column value for singleton (const) diff --git a/FWCore/Utilities/interface/Range.h b/FWCore/Utilities/interface/Range.h index e876b10334c34..59fc1a23de9d4 100644 --- a/FWCore/Utilities/interface/Range.h +++ b/FWCore/Utilities/interface/Range.h @@ -1,8 +1,6 @@ #ifndef FWCore_Utilities_Range_h #define FWCore_Utilities_Range_h -#include - namespace edm { /* *class which implements begin() and end() to use range-based loop with @@ -18,12 +16,6 @@ namespace edm { T end() const { return end_; } bool empty() const { return begin_ == end_; } - auto size() const { return end_ - begin_; } - - auto const& operator[](std::size_t idx) const { return *(begin_ + idx); } - - auto const& front() const { return *begin_; } - auto const& back() const { return *(end_ - 1); } private: const T begin_; diff --git a/FWCore/Utilities/interface/Span.h b/FWCore/Utilities/interface/Span.h new file mode 100644 index 0000000000000..9d4f16b2b17e8 --- /dev/null +++ b/FWCore/Utilities/interface/Span.h @@ -0,0 +1,37 @@ +#ifndef FWCore_Utilities_Span_h +#define FWCore_Utilities_Span_h + +#include + +namespace edm { + /* + *An edm::Span wraps begin() and end() iterators to a contiguous sequence + of objects with the first element of the sequence at position zero, + In other words the iterators should refer to random-access containers. + + To be replaced with std::Span in C++20. + */ + + template + class Span { + public: + Span(T begin, T end) : begin_(begin), end_(end) {} + + T begin() const { return begin_; } + T end() const { return end_; } + + bool empty() const { return begin_ == end_; } + auto size() const { return end_ - begin_; } + + auto const& operator[](std::size_t idx) const { return *(begin_ + idx); } + + auto const& front() const { return *begin_; } + auto const& back() const { return *(end_ - 1); } + + private: + const T begin_; + const T end_; + }; +}; // namespace edm + +#endif