LDMX Software
Range.h
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
14namespace acts_examples {
15
26template <typename Iterator>
27class 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
46template <typename Iterator>
47Range<Iterator> makeRange(Iterator begin, Iterator end) {
48 return Range<Iterator>(begin, end);
49}
50
51template <typename Iterator>
52Range<Iterator> makeRange(std::pair<Iterator, Iterator> range) {
53 return Range<Iterator>(range.first, range.second);
54}
55
56} // namespace acts_examples
A wrapper around a pair of iterators to simplify range-based loops.
Definition Range.h:27