ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Range.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Range.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
11 #include <iterator>
12 #include <utility>
13 
14 namespace FW {
15 
26 template <typename Iterator>
27 class Range {
28  public:
29  Range(Iterator b, Iterator e) : m_begin(b), m_end(e) {}
30  Range(Range&&) = default;
31  Range(const Range&) = default;
32  ~Range() = default;
33  Range& operator=(Range&&) = default;
34  Range& operator=(const Range&) = default;
35 
36  Iterator begin() const { return m_begin; }
37  Iterator end() const { return m_end; }
38  bool empty() const { return m_begin == m_end; }
39  std::size_t size() const { return std::distance(m_begin, m_end); }
40 
41  private:
42  Iterator m_begin;
43  Iterator m_end;
44 };
45 
46 template <typename Iterator>
47 Range<Iterator> makeRange(Iterator begin, Iterator end) {
48  return Range<Iterator>(begin, end);
49 }
50 
51 template <typename Iterator>
52 Range<Iterator> makeRange(std::pair<Iterator, Iterator> range) {
53  return Range<Iterator>(range.first, range.second);
54 }
55 
56 } // namespace FW