ATLAS Offline Software
Loading...
Searching...
No Matches
CombinationsIterator.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef TRIG_HLTJETHYPO_COMBINATIONSITERATOR_H
6#define TRIG_HLTJETHYPO_COMBINATIONSITERATOR_H
7
10
11#include <vector>
12#include <iterator>
13#include <iosfwd>
14
15/*
16 * CombinatonsIterator is a forward iterator. It iterates over
17 * combinations (n choose k) gnerated by a CombinationsGenerator instance.
18 * of a HypoJetVector.
19 *
20 * Dereferencing the iterator returns a HypoJetVector corresponding
21 * to the current combination.
22 *
23 * CombinationsIterator can generates the
24 * end of iteration CombinationsIterator
25 */
26
28
29 public:
30 using iterator_category = std::forward_iterator_tag;
31 using difference_type = std::ptrdiff_t;
35
36
37 friend std::ostream& operator << (std::ostream&, const CombinationsIterator&);
38 CombinationsIterator(std::size_t k,
39 const HypoJetVector& input_vals,
40 bool end=false);
41
43
44
46
47
49
50 // pre-increment
52 m_end = m_gen.bump();
53 auto indices = m_gen.get();
54
55 // overwrite m_vals according to the combinations indicies
56 std::transform(indices.cbegin(),
57 indices.cend(),
58 m_vals.begin(),
59 [iv = this->m_input_vals](const auto& ind) {
60 return iv.at(ind);
61 });
62
63 return *this;
64 }
65
66 // post-increment
68 CombinationsIterator tmp = *this;
69 ++(*this);
70 return tmp;
71 }
72
73
74 // create an end of iteration marker from a CombinationsIterator
76
77 // enable an equality test with an end iterator
78 friend bool operator==(const CombinationsIterator& a,
79 const CombinationsIterator& b) {
80 return a.m_end == b.m_end and
81 a.m_k == b.m_k and
82 a.m_input_vals == b.m_input_vals;
83
84
85 }
86
87
88 // enable an inequality test with an end iterator
89 friend bool operator!=(const CombinationsIterator& a,
90 const CombinationsIterator& b) {
91 return !(a==b);
92 }
93
94
95 private:
97 std::size_t m_k{0};
98
101
102 bool m_end{false};
103};
104
105std::ostream& operator << (std::ostream& os, const CombinationsIterator& iter);
106
107
108#endif
109
std::ostream & operator<<(std::ostream &os, const CombinationsIterator &iter)
std::vector< pHypoJet > HypoJetVector
Definition HypoJetDefs.h:27
static Double_t a
generate all possible combinations of objects
friend std::ostream & operator<<(std::ostream &, const CombinationsIterator &)
CombinationsIterator operator++(int)
std::forward_iterator_tag iterator_category
CombinationsIterator(std::size_t k, const HypoJetVector &input_vals, bool end=false)
friend bool operator==(const CombinationsIterator &a, const CombinationsIterator &b)
friend bool operator!=(const CombinationsIterator &a, const CombinationsIterator &b)
CombinationsGenerator m_gen
CombinationsIterator endIter() const
CombinationsIterator & operator++()