CMS 3D CMS Logo

CommutativePairs.h
Go to the documentation of this file.
1 #ifndef RecoParticleFlow_PFProducer_CommutativePairs_h
2 #define RecoParticleFlow_PFProducer_CommutativePairs_h
3 
4 #include <utility>
5 #include <vector>
6 
13 template <class T>
15 public:
16  // Insert a new pair
17  void insert(T const& a, T const& b) { pairs_.emplace_back(a, b); }
18 
19  // Check if this contains (a,b) or (b,a)
20  bool contains(T const& a, T const& b) const {
21  for (auto const& p : pairs_) {
22  if ((a == p.first && b == p.second) || (b == p.first && a == p.second)) {
23  return true;
24  }
25  }
26  return false;
27  }
28 
29  // Check if this contains (a,b) or (b,a), where b is arbitrary
30  bool contains(T const& a) const {
31  for (auto const& p : pairs_) {
32  if (a == p.first || a == p.second) {
33  return true;
34  }
35  }
36  return false;
37  }
38 
41  pairs_.insert(pairs_.end(), other.pairs_.begin(), other.pairs_.end());
42  }
43 
44 private:
45  std::vector<std::pair<T, T>> pairs_;
46 };
47 
48 #endif
void concatenate(CommutativePairs< T > const &other)
Add the pairs from another CommutativePairs to this.
bool contains(T const &a, T const &b) const
void insert(T const &a, T const &b)
bool contains(T const &a) const
double b
Definition: hdecay.h:118
double a
Definition: hdecay.h:119
std::vector< std::pair< T, T > > pairs_
long double T